Description:
Expand logging options.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r262:7c8bc6d7bf40 -

@@ -96,10 +96,10
96 96
97 97 var contractCount = contractOrganizations.Count();
98 98 OrganizationType organization_type = OrganizationType.Unspecified;
99 var organization_index = random_generator.Next(0, contractCount);
99 100
100 101 if (contractCount > 0)
101 102 {
102 var organization_index = random_generator.Next(0, contractCount);
103 103 organization_type = GetComponent<OrganizationTypeComponent>(contractOrganizations[organization_index]).type;
104 104 }
105 105
@@ -1,9 +1,13
1 1
2 2 using System;
3 using System.Collections;
3 4 using System.Collections.Generic;
4 5 using System.Runtime.CompilerServices;
5 6 using System.Reflection;
6 // using System.Linq;
7 using System.Linq;
8
9
10 using JM.LinqFaster;
7 11
8 12 /* Tiny log library inspired by Python's logging and Glögi.
9 13 */
@@ -25,6 +29,8
25 29
26 30 // private
27 31 //
32
33 public static List<ITuple> entries = new List<ITuple>();
28 34 private static Dictionary<LogLevel, (ConsoleColor, ConsoleColor)> mappings = new Dictionary<LogLevel, (ConsoleColor, ConsoleColor)>
29 35 {
30 36 {LogLevel.Critical, (ConsoleColor.White, ConsoleColor.Red)},
@@ -62,7 +68,26
62 68 Console.Out.WriteLine(string.Format(" {0} [{1}:{2}]", message, path, lineNumber));
63 69 }
64 70
65 public static void Log(LogLevel level, string message,
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 91 [CallerLineNumber] int lineNumber = 0,
67 92 [CallerMemberName] string caller = null,
68 93 [CallerFilePath] string path = "")
@@ -71,6 +96,48
71 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 141 public static void Critical(string message,
75 142 [CallerLineNumber] int lineNumber = 0,
76 143 [CallerMemberName] string caller = null,
@@ -171,6 +171,12
171 171 Logging.Debug("Test");
172 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 180 Logging.Spy(new {debugInfo.cameraPosition, debugInfo.updateTime, test = 9.0f /2});
175 181
176 182 }
@@ -35,7 +35,7
35 35
36 36 var result = grammar.Flatten(variableString);
37 37 #if DEBUG
38 Logging.Debug(variableString);
38 Logging.Trace(String.Format("{0}: {1}", variableString, result));
39 39 #endif
40 40
41 41 return new NewsItem {
You need to be logged in to leave comments. Login now