Description:
Expand logging options.
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
@@ -96,10 +96,10 | |||||
|
96 |
|
96 | ||
|
97 | var contractCount = contractOrganizations.Count(); |
|
97 | var contractCount = contractOrganizations.Count(); |
|
98 | OrganizationType organization_type = OrganizationType.Unspecified; |
|
98 | OrganizationType organization_type = OrganizationType.Unspecified; |
|
|
99 | var organization_index = random_generator.Next(0, contractCount); | ||
|
99 |
|
100 | ||
|
100 | if (contractCount > 0) |
|
101 | if (contractCount > 0) |
|
101 | { |
|
102 | { |
|
102 | var organization_index = random_generator.Next(0, contractCount); |
|
||
|
103 | organization_type = GetComponent<OrganizationTypeComponent>(contractOrganizations[organization_index]).type; |
|
103 | organization_type = GetComponent<OrganizationTypeComponent>(contractOrganizations[organization_index]).type; |
|
104 | } |
|
104 | } |
|
105 |
|
105 |
@@ -1,9 +1,13 | |||||
|
1 |
|
1 | ||
|
2 | using System; |
|
2 | using System; |
|
|
3 | using System.Collections; | ||
|
3 | using System.Collections.Generic; |
|
4 | using System.Collections.Generic; |
|
4 | using System.Runtime.CompilerServices; |
|
5 | using System.Runtime.CompilerServices; |
|
5 | using System.Reflection; |
|
6 | using System.Reflection; |
|
6 |
|
|
7 | using System.Linq; |
|
|
8 | |||
|
|
9 | |||
|
|
10 | using JM.LinqFaster; | ||
|
7 |
|
11 | ||
|
8 | /* Tiny log library inspired by Python's logging and Glögi. |
|
12 | /* Tiny log library inspired by Python's logging and Glögi. |
|
9 | */ |
|
13 | */ |
@@ -25,6 +29,8 | |||||
|
25 |
|
29 | ||
|
26 | // private |
|
30 | // private |
|
27 | // |
|
31 | // |
|
|
32 | |||
|
|
33 | public static List<ITuple> entries = new List<ITuple>(); | ||
|
28 | private static Dictionary<LogLevel, (ConsoleColor, ConsoleColor)> mappings = new Dictionary<LogLevel, (ConsoleColor, ConsoleColor)> |
|
34 | private static Dictionary<LogLevel, (ConsoleColor, ConsoleColor)> mappings = new Dictionary<LogLevel, (ConsoleColor, ConsoleColor)> |
|
29 | { |
|
35 | { |
|
30 | {LogLevel.Critical, (ConsoleColor.White, ConsoleColor.Red)}, |
|
36 | {LogLevel.Critical, (ConsoleColor.White, ConsoleColor.Red)}, |
@@ -62,7 +68,26 | |||||
|
62 | Console.Out.WriteLine(string.Format(" {0} [{1}:{2}]", message, path, lineNumber)); |
|
68 | Console.Out.WriteLine(string.Format(" {0} [{1}:{2}]", message, path, lineNumber)); |
|
63 | } |
|
69 | } |
|
64 |
|
70 | ||
|
65 |
|
|
71 | private static void Log_<T>(LogLevel level, string message, T data, |
|
|
72 | int lineNumber, string caller, string path) | ||
|
|
73 | where T : ITuple | ||
|
|
74 | { | ||
|
|
75 | Logging.entries.Add(data); | ||
|
|
76 | // var d = data.GetType().GetProperties().ToDictionary(Info => Info.Name, Info => Info.GetValue(data)); | ||
|
|
77 | // var data_strings = data.GetType().GetProperties().Select(Info => Info.Name + "=" + Info.GetValue(data).ToString()); | ||
|
|
78 | // var data_string = string.Join(", ", data_strings); | ||
|
|
79 | // var str = String.Format("{0} {1}", message, data_string); | ||
|
|
80 | Logging.Log_(level, message, lineNumber, caller, path); | ||
|
|
81 | } | ||
|
|
82 | |||
|
|
83 | private static void Log_(LogLevel level, string message, | ||
|
|
84 | int lineNumber, string caller, string path, params object[] objects) | ||
|
|
85 | { | ||
|
|
86 | String.Format(message, objects); | ||
|
|
87 | Logging.Log_(level, message, lineNumber, caller, path); | ||
|
|
88 | } | ||
|
|
89 | |||
|
|
90 | public static void Log(LogLevel level, string message, | ||
|
66 | [CallerLineNumber] int lineNumber = 0, |
|
91 | [CallerLineNumber] int lineNumber = 0, |
|
67 | [CallerMemberName] string caller = null, |
|
92 | [CallerMemberName] string caller = null, |
|
68 | [CallerFilePath] string path = "") |
|
93 | [CallerFilePath] string path = "") |
@@ -71,6 +96,48 | |||||
|
71 | Logging.Log_(level, message, lineNumber, caller, path); |
|
96 | Logging.Log_(level, message, lineNumber, caller, path); |
|
72 | } |
|
97 | } |
|
73 |
|
98 | ||
|
|
99 | /* | ||
|
|
100 | public static void Log<T>(LogLevel level, string message, T data, | ||
|
|
101 | [CallerLineNumber] int lineNumber = 0, | ||
|
|
102 | [CallerMemberName] string caller = null, | ||
|
|
103 | [CallerFilePath] string path = "") | ||
|
|
104 | //Constrain to Tuples and tuple-likes: | ||
|
|
105 | where T : ITuple, IStructuralEquatable, IStructuralComparable | ||
|
|
106 | { | ||
|
|
107 | Logging.Log_(level, message, data, lineNumber, caller, path); | ||
|
|
108 | }*/ | ||
|
|
109 | |||
|
|
110 | public static void Log<T>(LogLevel level, string message, T data, | ||
|
|
111 | [CallerLineNumber] int lineNumber = 0, | ||
|
|
112 | [CallerMemberName] string caller = null, | ||
|
|
113 | [CallerFilePath] string path = "") | ||
|
|
114 | //Constrain to Tuples and tuple-likes: | ||
|
|
115 | where T : class | ||
|
|
116 | { | ||
|
|
117 | |||
|
|
118 | var properties = new List<string>(); | ||
|
|
119 | |||
|
|
120 | foreach (var property in typeof(T).GetProperties()) | ||
|
|
121 | { | ||
|
|
122 | properties.Add(property.ToString() + "=" + property.GetValue(data)); | ||
|
|
123 | } | ||
|
|
124 | |||
|
|
125 | var message_data = message + " {" + String.Join(", ", properties) + "}"; | ||
|
|
126 | |||
|
|
127 | Logging.Log_(level, message_data, lineNumber, caller, path); | ||
|
|
128 | |||
|
|
129 | } | ||
|
|
130 | |||
|
|
131 | public static void Log(LogLevel level, string message, | ||
|
|
132 | object[] format, | ||
|
|
133 | [CallerLineNumber] int lineNumber = 0, | ||
|
|
134 | [CallerMemberName] string caller = null, | ||
|
|
135 | [CallerFilePath] string path = "") | ||
|
|
136 | { | ||
|
|
137 | |||
|
|
138 | Logging.Log_(level, message, lineNumber, caller, path, format); | ||
|
|
139 | } | ||
|
|
140 | |||
|
74 | public static void Critical(string message, |
|
141 | public static void Critical(string message, |
|
75 | [CallerLineNumber] int lineNumber = 0, |
|
142 | [CallerLineNumber] int lineNumber = 0, |
|
76 | [CallerMemberName] string caller = null, |
|
143 | [CallerMemberName] string caller = null, |
@@ -171,6 +171,12 | |||||
|
171 | Logging.Debug("Test"); |
|
171 | Logging.Debug("Test"); |
|
172 | Logging.Trace("Test"); |
|
172 | Logging.Trace("Test"); |
|
173 |
|
173 | ||
|
|
174 | |||
|
|
175 | // var t = (testa: 1, testb: 2); | ||
|
|
176 | //Logging.Log(LogLevel.Critical, "Test", t); | ||
|
|
177 | Logging.Log(LogLevel.Critical, "test", new{test=9.0f}); | ||
|
|
178 | //Logging.Log(LogLevel.Critical, "{0}", 0, null, "", 9.0f); | ||
|
|
179 | |||
|
174 | Logging.Spy(new {debugInfo.cameraPosition, debugInfo.updateTime, test = 9.0f /2}); |
|
180 | Logging.Spy(new {debugInfo.cameraPosition, debugInfo.updateTime, test = 9.0f /2}); |
|
175 |
|
181 | ||
|
176 | } |
|
182 | } |
@@ -35,7 +35,7 | |||||
|
35 |
|
35 | ||
|
36 | var result = grammar.Flatten(variableString); |
|
36 | var result = grammar.Flatten(variableString); |
|
37 | #if DEBUG |
|
37 | #if DEBUG |
|
38 |
Logging. |
|
38 | Logging.Trace(String.Format("{0}: {1}", variableString, result)); |
|
39 | #endif |
|
39 | #endif |
|
40 |
|
40 | ||
|
41 | return new NewsItem { |
|
41 | return new NewsItem { |
You need to be logged in to leave comments.
Login now