Skip to content

Commit 126b764

Browse files
committed
Add line and file info
1 parent 21f65e4 commit 126b764

File tree

7 files changed

+39
-11
lines changed

7 files changed

+39
-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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using S = System.String;
23
using P = System.Runtime.CompilerServices.CallerFilePathAttribute;
34
using M = System.Runtime.CompilerServices.CallerMemberNameAttribute;
@@ -10,18 +11,18 @@ public static class DebugChan{
1011
public static bool logToConsole;
1112
public static int? maxMessages = null;
1213

13-
public static Logger<string, object> logger;
14+
public static Logger<LogMessage, object> logger;
1415

16+
[Conditional("UNITY_EDITOR"), Conditional("DEBUG")]
1517
public static void Print(
1618
string arg, object source,
1719
[P] S path="", [M] S member="", [L] int line=0)
1820
{
1921
logger?.Log(
20-
arg,
21-
//new DebugInfo(path, member, line),
22+
new LogMessage(arg, path, member, line),
2223
RemapSource(source), maxMessages);
2324
if(logToConsole)
24-
Debug.Log(arg, source as UnityEngine.Object);
25+
UnityEngine.Debug.Log(arg, source as UnityEngine.Object);
2526
}
2627

2728
static object RemapSource(object arg){

Runtime/DebugChan/LogMessage.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
namespace Activ.Loggr{
22
public readonly struct LogMessage{
33

4+
#if UNITY_EDITOR_WIN
5+
const char pathsep = '\\';
6+
#else
7+
const char pathsep = '/';
8+
#endif
9+
410
readonly string message;
511
readonly LogInfo info;
12+
readonly string quickFormat;
613

714
public LogMessage(string message,
815
string path, string member, int line){
916
this.message = message;
1017
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));
1129
}
1230

1331
}}

0 commit comments

Comments
 (0)