-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cs
85 lines (71 loc) · 2 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
using System;
using UnityEngine;
namespace Magix.Diagnostics
{
public enum LogLevel
{
Verbose = 0,
Warning = 1,
Error = 2
}
enum LogType
{
Normal = 0,
Warning = 1,
Error = 2
}
public static class MagixLogger
{
public static LogLevel Level = LogLevel.Verbose;
public static void LogVerbose(string message)
{
if (Level > LogLevel.Verbose)
{
return;
}
Log("VERBOSE", message, LogType.Normal, Color.white);
}
public static void Log(string message)
{
if (Level > LogLevel.Warning)
{
return;
}
Log("INF", message, LogType.Normal, Color.white);
}
public static void LogWarn(string message)
{
if (Level > LogLevel.Warning)
{
return;
}
Log("WARN", message, LogType.Normal, Color.yellow);
}
public static void LogError(string message)
{
if (Level > LogLevel.Error)
{
return;
}
Log("ERR", message, LogType.Error, Color.red);
}
private static string GetTime()
{
return DateTime.Now.ToString("dd':'HH':'mm':'ss");
}
private static void Log(string category, string message, LogType type, Color color)
{
if (Level > LogLevel.Warning)
{
return;
}
var msg = string.Format("<color=#{0:X2}{1:X2}{2:X2}>{3}</color>{4}", (byte)(color.r * 255f), (byte)(color.g * 255f), (byte)(color.b * 255f), $"[LOG {category}] {GetTime()}]:", message);
if (type == LogType.Normal)
Debug.Log(msg);
else if (type == LogType.Warning)
Debug.LogWarning(msg);
else if (type == LogType.Error)
Debug.LogError(msg);
}
}
}