Skip to content

Commit 10c4748

Browse files
authored
Merge pull request #35 from eelstork/dev
Dev
2 parents a6ee80d + 126b764 commit 10c4748

File tree

10 files changed

+97
-11
lines changed

10 files changed

+97
-11
lines changed

Editor/Core/UI/LogWindow-DebugChan.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void DrawLoggerTextView(float time, int? height){
4242
}
4343

4444
string EvalTextContent(float time){
45-
var logger = (Activ.Loggr.Logger<string, object>) DebugChan.logger;
45+
var logger = (Activ.Loggr.Logger<LogMessage, object>) DebugChan.logger;
4646
if(logger == null){
4747
return ""; // "Debug-Chan: not running";
4848
}

Editor/Core/UI/LogWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void DrawTextView(string text, int? height, ref Vector2 scroll){
125125
void ConfigTextAreaStyle(){
126126
var f = monofont;
127127
if(f == null) Debug.LogError("font not available");
128-
var style = GUI.skin.button;
128+
var style = GUI.skin.textArea;
129129
style.font = f;
130130
style.fontSize = FontSize;
131131
style.normal.textColor = Color.white * 0.9f;

Editor/Core/UI/LogWindowModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ public class LogWindowModel{
1414
public int? currentFrame;
1515
public PrologHistory filtered{ get; private set; }
1616
PrologFilter filter;
17-
public PrologFrame pgRange; // selected prolog range
18-
public Range<string> dcRange; // selected debug-chan range
17+
public PrologFrame pgRange; // selected prolog range
18+
public Range<LogMessage> dcRange; // selected debug-chan range
1919

2020
public LogWindowModel(){
2121
PrologLogger.onFrame += OnPrologFrame;

Editor/DebugChan/LoggingManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static LoggingManager(){
1313
static void OnPlayState(PlayModeStateChange state){
1414
switch(state){
1515
case PlayModeStateChange.EnteredPlayMode:
16-
DebugChan.logger = new Logger<string, object>();
16+
DebugChan.logger = new Logger<LogMessage, object>();
1717
DebugChan.logToConsole = Config.logToConsole;
1818
DebugChan.maxMessages = Config.maxMessages == 0
1919
? (int?)null

Runtime/Core/Range.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,18 @@ public string Format(float time)
3838
=> FormatSpan(time) + "\n" + messages.Format();
3939

4040
string FormatSpan()
41-
=> $"[ {start.frame}{end.frame} ]";
41+
=> spanFormat + ' ' + durationFormat;
4242

4343
string FormatSpan(float time)
44-
=> $"[ {start.frame}{end.frame} ] {(time - start.time):0.00}s ago ";
44+
=> spanFormat + $" {(time - start.time):0.00}s ago "
45+
+ durationFormat;
46+
47+
string spanFormat => duration == 0 ? $"[{start.frame}]"
48+
: $"[{start.frame}{end.frame}]";
49+
50+
string durationFormat
51+
=> duration == 0 ? null : $"({duration:0.000}s)";
52+
53+
float duration => end.time - start.time;
4554

4655
}}

Runtime/DebugChan/DebugChan.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
using System.Diagnostics;
2+
using S = System.String;
3+
using P = System.Runtime.CompilerServices.CallerFilePathAttribute;
4+
using M = System.Runtime.CompilerServices.CallerMemberNameAttribute;
5+
using L = System.Runtime.CompilerServices.CallerLineNumberAttribute;
16
using UnityEngine;
27
using Activ.Loggr; using Activ.LogChan;
38

@@ -6,12 +11,18 @@ public static class DebugChan{
611
public static bool logToConsole;
712
public static int? maxMessages = null;
813

9-
public static Logger<string, object> logger;
14+
public static Logger<LogMessage, object> logger;
1015

11-
public static void Print(string arg, object source){
12-
logger?.Log(arg, RemapSource(source), maxMessages);
16+
[Conditional("UNITY_EDITOR"), Conditional("DEBUG")]
17+
public static void Print(
18+
string arg, object source,
19+
[P] S path="", [M] S member="", [L] int line=0)
20+
{
21+
logger?.Log(
22+
new LogMessage(arg, path, member, line),
23+
RemapSource(source), maxMessages);
1324
if(logToConsole)
14-
Debug.Log(arg, source as UnityEngine.Object);
25+
UnityEngine.Debug.Log(arg, source as UnityEngine.Object);
1526
}
1627

1728
static object RemapSource(object arg){

Runtime/DebugChan/LogInfo.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Activ.Loggr{
2+
public readonly struct LogInfo{
3+
4+
readonly string path, member;
5+
readonly int line;
6+
7+
public LogInfo(string path, string member, int line){
8+
this.path = path;
9+
this.member = member;
10+
this.line = line;
11+
}
12+
13+
}}

Runtime/DebugChan/LogInfo.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/DebugChan/LogMessage.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace Activ.Loggr{
2+
public readonly struct LogMessage{
3+
4+
#if UNITY_EDITOR_WIN
5+
const char pathsep = '\\';
6+
#else
7+
const char pathsep = '/';
8+
#endif
9+
10+
readonly string message;
11+
readonly LogInfo info;
12+
readonly string quickFormat;
13+
14+
public LogMessage(string message,
15+
string path, string member, int line){
16+
this.message = message;
17+
this.info = new LogInfo(path, member, line);
18+
var filename = QuickParseFileName(path);
19+
quickFormat =
20+
line.ToString().PadLeft(3, '0') + "| "
21+
+ filename + "." + member + ": " + message;
22+
}
23+
24+
override public string ToString() => quickFormat;
25+
26+
static string QuickParseFileName(string arg){
27+
var i = arg.LastIndexOf(pathsep);
28+
return arg.Substring(i + 1, arg.Length - (i + 4));
29+
}
30+
31+
}}

Runtime/DebugChan/LogMessage.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)