-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Logger.cs
303 lines (257 loc) · 9.92 KB
/
Logger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
using System;
// ReSharper disable InconsistentNaming
namespace IPA.Logging
{
/// <summary>
/// The logger base class. Provides the format for console logs.
/// </summary>
public abstract class Logger
{
private static Logger _log;
internal static Logger log
{
get
{
if (_log == null)
_log = new StandardLogger("IPA");
return _log;
}
}
private static StandardLogger _stdout;
internal static StandardLogger stdout
{
get
{
if (_stdout == null)
_stdout = new StandardLogger("_");
return _stdout;
}
}
internal static Logger updater => log.GetChildLogger("Updater");
internal static Logger libLoader => log.GetChildLogger("LibraryLoader");
internal static Logger loader => log.GetChildLogger("Loader");
internal static Logger features => loader.GetChildLogger("Features");
internal static Logger config => log.GetChildLogger("Config");
internal static bool LogCreated => _log != null || UnityLogProvider.Logger != null;
/// <summary>
/// The standard format for log messages.
/// </summary>
/// <value>the format for the standard loggers to print in</value>
public static string LogFormat { get; protected internal set; } = "[{3} @ {2:HH:mm:ss} | {1}] {0}";
/// <summary>
/// An enum specifying the level of the message. Resembles Syslog.
/// </summary>
public enum Level : byte
{
/// <summary>
/// No associated level. These never get shown.
/// </summary>
None = 0,
/// <summary>
/// A trace message. These are ignored *incredibly* early.
/// </summary>
Trace = 32,
/// <summary>
/// A debug message.
/// </summary>
Debug = 1,
/// <summary>
/// An informational message.
/// </summary>
Info = 2,
/// <summary>
/// A notice. More significant than Info, but less than a warning.
/// </summary>
Notice = 32,
/// <summary>
/// A warning message.
/// </summary>
Warning = 4,
/// <summary>
/// An error message.
/// </summary>
Error = 8,
/// <summary>
/// A critical error message.
/// </summary>
Critical = 16
}
/// <summary>
/// An enum providing log level filters.
/// </summary>
[Flags]
public enum LogLevel : byte
{
/// <summary>
/// Allow no messages through.
/// </summary>
None = Level.None,
/// <summary>
/// Only shows Trace messages.
/// </summary>
TraceOnly = Level.Trace,
/// <summary>
/// Only shows Debug messages.
/// </summary>
DebugOnly = Level.Debug,
/// <summary>
/// Only shows info messages.
/// </summary>
InfoOnly = Level.Info,
/// <summary>
/// Only shows notice messages.
/// </summary>
NoticeOnly = Level.Notice,
/// <summary>
/// Only shows Warning messages.
/// </summary>
WarningOnly = Level.Warning,
/// <summary>
/// Only shows Error messages.
/// </summary>
ErrorOnly = Level.Error,
/// <summary>
/// Only shows Critical messages.
/// </summary>
CriticalOnly = Level.Critical,
/// <summary>
/// Shows all messages error and up.
/// </summary>
ErrorUp = ErrorOnly | CriticalOnly,
/// <summary>
/// Shows all messages warning and up.
/// </summary>
WarningUp = WarningOnly | ErrorUp,
/// <summary>
/// Shows all messages Notice and up.
/// </summary>
NoticeUp = WarningUp | NoticeOnly,
/// <summary>
/// Shows all messages info and up.
/// </summary>
InfoUp = InfoOnly | NoticeUp,
/// <summary>
/// Shows all messages debug and up.
/// </summary>
DebugUp = DebugOnly | InfoUp,
/// <summary>
/// Shows all messages.
/// </summary>
All = TraceOnly | DebugUp,
/// <summary>
/// Used for when the level is undefined.
/// </summary>
Undefined = Byte.MaxValue
}
/// <summary>
/// A basic log function.
/// </summary>
/// <param name="level">the level of the message</param>
/// <param name="message">the message to log</param>
public abstract void Log(Level level, string message);
/// <summary>
/// A basic log function taking an exception to log.
/// </summary>
/// <param name="level">the level of the message</param>
/// <param name="e">the exception to log</param>
public virtual void Log(Level level, Exception e) => Log(level, e.ToString());
/// <summary>
/// Sends a trace message.
/// Equivalent to `Log(Level.Trace, message);`
/// </summary>
/// <seealso cref="Log(Level, string)"/>
/// <param name="message">the message to log</param>
public virtual void Trace(string message) => Log(Level.Trace, message);
/// <summary>
/// Sends an exception as a trace message.
/// Equivalent to `Log(Level.Trace, e);`
/// </summary>
/// <seealso cref="Log(Level, Exception)"/>
/// <param name="e">the exception to log</param>
public virtual void Trace(Exception e) => Log(Level.Trace, e);
/// <summary>
/// Sends a debug message.
/// Equivalent to `Log(Level.Debug, message);`
/// </summary>
/// <seealso cref="Log(Level, string)"/>
/// <param name="message">the message to log</param>
public virtual void Debug(string message) => Log(Level.Debug, message);
/// <summary>
/// Sends an exception as a debug message.
/// Equivalent to `Log(Level.Debug, e);`
/// </summary>
/// <seealso cref="Log(Level, Exception)"/>
/// <param name="e">the exception to log</param>
public virtual void Debug(Exception e) => Log(Level.Debug, e);
/// <summary>
/// Sends an info message.
/// Equivalent to `Log(Level.Info, message);`
/// </summary>
/// <seealso cref="Log(Level, string)"/>
/// <param name="message">the message to log</param>
public virtual void Info(string message) => Log(Level.Info, message);
/// <summary>
/// Sends an exception as an info message.
/// Equivalent to `Log(Level.Info, e);`
/// </summary>
/// <seealso cref="Log(Level, Exception)"/>
/// <param name="e">the exception to log</param>
public virtual void Info(Exception e) => Log(Level.Info, e);
/// <summary>
/// Sends a notice message.
/// Equivalent to `Log(Level.Notice, message);`
/// </summary>
/// <seealso cref="Log(Level, string)"/>
/// <param name="message">the message to log</param>
public virtual void Notice(string message) => Log(Level.Notice, message);
/// <summary>
/// Sends an exception as a notice message.
/// Equivalent to `Log(Level.Notice, e);`
/// </summary>
/// <seealso cref="Log(Level, Exception)"/>
/// <param name="e">the exception to log</param>
public virtual void Notice(Exception e) => Log(Level.Notice, e);
/// <summary>
/// Sends a warning message.
/// Equivalent to `Log(Level.Warning, message);`
/// </summary>
/// <seealso cref="Log(Level, string)"/>
/// <param name="message">the message to log</param>
public virtual void Warn(string message) => Log(Level.Warning, message);
/// <summary>
/// Sends an exception as a warning message.
/// Equivalent to `Log(Level.Warning, e);`
/// </summary>
/// <seealso cref="Log(Level, Exception)"/>
/// <param name="e">the exception to log</param>
public virtual void Warn(Exception e) => Log(Level.Warning, e);
/// <summary>
/// Sends an error message.
/// Equivalent to `Log(Level.Error, message);`
/// </summary>
/// <seealso cref="Log(Level, string)"/>
/// <param name="message">the message to log</param>
public virtual void Error(string message) => Log(Level.Error, message);
/// <summary>
/// Sends an exception as an error message.
/// Equivalent to `Log(Level.Error, e);`
/// </summary>
/// <seealso cref="Log(Level, Exception)"/>
/// <param name="e">the exception to log</param>
public virtual void Error(Exception e) => Log(Level.Error, e);
/// <summary>
/// Sends a critical message.
/// Equivalent to `Log(Level.Critical, message);`
/// </summary>
/// <seealso cref="Log(Level, string)"/>
/// <param name="message">the message to log</param>
public virtual void Critical(string message) => Log(Level.Critical, message);
/// <summary>
/// Sends an exception as a critical message.
/// Equivalent to `Log(Level.Critical, e);`
/// </summary>
/// <seealso cref="Log(Level, Exception)"/>
/// <param name="e">the exception to log</param>
public virtual void Critical(Exception e) => Log(Level.Critical, e);
}
}