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 | 875 | additionalInfo.Add("mouse delta", delta.ToString()); |
|
876 | 876 | |
|
877 | 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 | 880 | debugWindow.Layout(debugInfo, additionalInfo, ref show_another_window); |
|
880 | 881 |
@@ -25,13 +25,22 | |||
|
25 | 25 | Trace, |
|
26 | 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 | 35 | public class Logging |
|
29 | 36 | { |
|
30 | 37 | |
|
31 | 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 | 44 | public static string logFileName = string.Format("log_{0:yyyyMMdd_HHmm}.txt", DateTime.Now); |
|
36 | 45 | |
|
37 | 46 | public static StreamWriter logFile = File.CreateText(logFileName); |
@@ -54,6 +63,9 | |||
|
54 | 63 | { |
|
55 | 64 | var timestamp = DateTime.Now; |
|
56 | 65 | |
|
66 | if ( (level < minimumConsoleLevel) | |
|
67 | || level == LogLevel.Spy) | |
|
68 | { | |
|
57 | 69 | var start_foreground = Console.ForegroundColor; |
|
58 | 70 | var start_background = Console.BackgroundColor; |
|
59 | 71 | |
@@ -61,25 +73,28 | |||
|
61 | 73 | |
|
62 | 74 | Console.ForegroundColor = new_foreground; |
|
63 | 75 | Console.BackgroundColor = new_background; |
|
64 | ||
|
65 | 76 | //29/Apr/2021 22:43:30 |
|
66 | 77 | Console.Out.Write(string.Format("[{0}] {1}", timestamp.ToString("s"), level.ToString())); |
|
67 | 78 | |
|
68 | ||
|
69 | 79 | Console.ForegroundColor = start_foreground; |
|
70 | 80 | Console.BackgroundColor = start_background; |
|
71 | 81 | |
|
72 | 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 | 93 | private static void Log_<T>(LogLevel level, string message, T data, |
|
79 | 94 | int lineNumber, string caller, string path) |
|
80 | 95 | where T : ITuple |
|
81 | 96 | { |
|
82 | Logging.entries.Add(data); | |
|
97 | // Logging.entries.Add(data); | |
|
83 | 98 | // var d = data.GetType().GetProperties().ToDictionary(Info => Info.Name, Info => Info.GetValue(data)); |
|
84 | 99 | // var data_strings = data.GetType().GetProperties().Select(Info => Info.Name + "=" + Info.GetValue(data).ToString()); |
|
85 | 100 | // var data_string = string.Join(", ", data_strings); |
You need to be logged in to leave comments.
Login now