Description:
Add entry-based logging.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -875,6 +875,7 | |||||
|
875 | additionalInfo.Add("mouse delta", delta.ToString()); |
|
875 | additionalInfo.Add("mouse delta", delta.ToString()); |
|
876 |
|
876 | ||
|
877 | additionalInfo.Add("Tracery Test", this.output); |
|
877 | additionalInfo.Add("Tracery Test", this.output); |
|
|
878 | additionalInfo.Add("Log Entry", string.Format("{0} {1}", Logging.entries[Logging.entries.Count-1].level, Logging.entries[Logging.entries.Count-1].message)); | ||
|
878 |
|
879 | ||
|
879 | debugWindow.Layout(debugInfo, additionalInfo, ref show_another_window); |
|
880 | debugWindow.Layout(debugInfo, additionalInfo, ref show_another_window); |
|
880 |
|
881 |
@@ -25,13 +25,22 | |||||
|
25 | Trace, |
|
25 | Trace, |
|
26 | Spy |
|
26 | Spy |
|
27 | } |
|
27 | } |
|
|
28 | |||
|
|
29 | public struct LogEntry { | ||
|
|
30 | public DateTime timestamp; | ||
|
|
31 | public string message; | ||
|
|
32 | public LogLevel level; | ||
|
|
33 | public ITuple data; | ||
|
|
34 | } | ||
|
28 | public class Logging |
|
35 | public class Logging |
|
29 | { |
|
36 | { |
|
30 |
|
37 | ||
|
31 | // private |
|
38 | // private |
|
32 | // |
|
39 | // |
|
33 |
|
40 | ||
|
34 | public static List<ITuple> entries = new List<ITuple>(); |
|
41 | public static LogLevel minimumConsoleLevel = LogLevel.Info; |
|
|
42 | |||
|
|
43 | public static List<LogEntry> entries = new List<LogEntry>(); | ||
|
35 | public static string logFileName = string.Format("log_{0:yyyyMMdd_HHmm}.txt", DateTime.Now); |
|
44 | public static string logFileName = string.Format("log_{0:yyyyMMdd_HHmm}.txt", DateTime.Now); |
|
36 |
|
45 | ||
|
37 | public static StreamWriter logFile = File.CreateText(logFileName); |
|
46 | public static StreamWriter logFile = File.CreateText(logFileName); |
@@ -54,6 +63,9 | |||||
|
54 | { |
|
63 | { |
|
55 | var timestamp = DateTime.Now; |
|
64 | var timestamp = DateTime.Now; |
|
56 |
|
65 | ||
|
|
66 | if ( (level < minimumConsoleLevel) | ||
|
|
67 | || level == LogLevel.Spy) | ||
|
|
68 | { | ||
|
57 | var start_foreground = Console.ForegroundColor; |
|
69 | var start_foreground = Console.ForegroundColor; |
|
58 | var start_background = Console.BackgroundColor; |
|
70 | var start_background = Console.BackgroundColor; |
|
59 |
|
71 | ||
@@ -61,25 +73,28 | |||||
|
61 |
|
73 | ||
|
62 | Console.ForegroundColor = new_foreground; |
|
74 | Console.ForegroundColor = new_foreground; |
|
63 | Console.BackgroundColor = new_background; |
|
75 | Console.BackgroundColor = new_background; |
|
64 |
|
|||
|
65 | //29/Apr/2021 22:43:30 |
|
76 | //29/Apr/2021 22:43:30 |
|
66 | Console.Out.Write(string.Format("[{0}] {1}", timestamp.ToString("s"), level.ToString())); |
|
77 | Console.Out.Write(string.Format("[{0}] {1}", timestamp.ToString("s"), level.ToString())); |
|
67 |
|
78 | ||
|
68 |
|
|||
|
69 | Console.ForegroundColor = start_foreground; |
|
79 | Console.ForegroundColor = start_foreground; |
|
70 | Console.BackgroundColor = start_background; |
|
80 | Console.BackgroundColor = start_background; |
|
71 |
|
81 | ||
|
72 | Console.Out.WriteLine(string.Format(" {0} [{1}:{2}]", message, path, lineNumber)); |
|
82 | Console.Out.WriteLine(string.Format(" {0} [{1}:{2}]", message, path, lineNumber)); |
|
|
83 | } | ||
|
|
84 | |||
|
|
85 | logFile.WriteLine(string.Format("[{0}] {1} {2} [{3}:{4}]", timestamp.ToString("s"), level.ToString(), message, path, lineNumber)); | ||
|
73 |
|
86 | ||
|
74 |
|
87 | ||
|
75 | logFile.WriteLine("[{0}] {1} {0} [{1}:{2}]"); |
|
88 | Logging.entries.Add(new LogEntry{timestamp = timestamp, |
|
|
89 | level = level, | ||
|
|
90 | message = message}); | ||
|
76 | } |
|
91 | } |
|
77 |
|
92 | ||
|
78 | private static void Log_<T>(LogLevel level, string message, T data, |
|
93 | private static void Log_<T>(LogLevel level, string message, T data, |
|
79 | int lineNumber, string caller, string path) |
|
94 | int lineNumber, string caller, string path) |
|
80 | where T : ITuple |
|
95 | where T : ITuple |
|
81 | { |
|
96 | { |
|
82 | Logging.entries.Add(data); |
|
97 | // Logging.entries.Add(data); |
|
83 | // var d = data.GetType().GetProperties().ToDictionary(Info => Info.Name, Info => Info.GetValue(data)); |
|
98 | // var d = data.GetType().GetProperties().ToDictionary(Info => Info.Name, Info => Info.GetValue(data)); |
|
84 | // var data_strings = data.GetType().GetProperties().Select(Info => Info.Name + "=" + Info.GetValue(data).ToString()); |
|
99 | // var data_strings = data.GetType().GetProperties().Select(Info => Info.Name + "=" + Info.GetValue(data).ToString()); |
|
85 | // var data_string = string.Join(", ", data_strings); |
|
100 | // var data_string = string.Join(", ", data_strings); |
You need to be logged in to leave comments.
Login now