-
Notifications
You must be signed in to change notification settings - Fork 53
/
Logger.cs
123 lines (109 loc) · 3.54 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using UnityEngine;
namespace KMP
{
public static class Log
{
private static bool useDelayedLogging = false;
private static Queue<string> delayedDebugQueue = new Queue<string>();
private static Queue<string> delayedWarningQueue = new Queue<string>();
private static Queue<string> delayedErrorQueue = new Queue<string>();
public enum LogLevels : int
{
Debug = 0,
Activity = 5,
Info = 10,
Notice = 20,
Warning = 30,
Error = 40,
}
public static LogLevels MinLogLevel { get; set; }
private static void WriteLog(LogLevels level, string format, params object[] args)
{
if (level < MinLogLevel)
{
return;
}
string output = string.Format("[{0}] : {1}", level.ToString(), string.Format(format, args));
switch (level)
{
case LogLevels.Debug:
case LogLevels.Activity:
case LogLevels.Info:
case LogLevels.Notice:
if (useDelayedLogging)
{
delayedDebugQueue.Enqueue(output);
}
else
{
UnityEngine.Debug.Log(output);
}
break;
case LogLevels.Warning:
if (useDelayedLogging)
{
delayedWarningQueue.Enqueue(output);
}
else
{
UnityEngine.Debug.LogWarning(output);
}
break;
case LogLevels.Error:
if (useDelayedLogging)
{
delayedErrorQueue.Enqueue(output);
}
else
{
UnityEngine.Debug.LogError(output);
}
break;
}
}
public static void WriteDelayedLog()
{
while (delayedDebugQueue.Count > 0)
{
UnityEngine.Debug.Log(delayedDebugQueue.Dequeue());
}
while (delayedWarningQueue.Count > 0)
{
UnityEngine.Debug.LogWarning(delayedWarningQueue.Dequeue());
}
while (delayedErrorQueue.Count > 0)
{
UnityEngine.Debug.LogError(delayedErrorQueue.Dequeue());
}
}
public static void Debug(string format, params object[] args)
{
WriteLog(LogLevels.Debug, format, args);
}
public static void Activity(string format, params object[] args)
{
WriteLog(LogLevels.Activity, format, args);
}
public static void Info(string format, params object[] args)
{
WriteLog(LogLevels.Info, format, args);
}
public static void Notice(string format, params object[] args)
{
WriteLog(LogLevels.Notice, format, args);
}
public static void Warning(string format, params object[] args)
{
WriteLog(LogLevels.Warning, format, args);
}
public static void Error(string format, params object[] args)
{
WriteLog(LogLevels.Error, format, args);
}
}
}