forked from RemoteTechnologiesGroup/RemoteTech
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTLog.cs
More file actions
134 lines (120 loc) · 4.96 KB
/
Copy pathRTLog.cs
File metadata and controls
134 lines (120 loc) · 4.96 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
namespace RemoteTech
{
/// <summary>
/// Different log levels to log messages for debugging.
/// </summary>
public enum RTLogLevel
{
LVL1,
LVL2,
LVL3,
LVL4,
API,
Assembly
};
public static class RTLog
{
/// <summary>On true the verbose-Methods will notify their messages</summary>
private static readonly bool verboseLogging;
/// <summary>debug log list</summary>
public static readonly Dictionary<RTLogLevel, List<string>> RTLogList = new Dictionary<RTLogLevel, List<string>>();
static RTLog()
{
verboseLogging = GameSettings.VERBOSE_DEBUG_LOG;
#region ON-DEBUGMODE
#if DEBUG
// always set the verboseLogging to true on debug mode
verboseLogging = true;
// initialize debug list
foreach (RTLogLevel lvl in Enum.GetValues(typeof(RTLogLevel)))
{
RTLogList.Add(lvl, new List<string>());
}
#endif
#endregion
}
/// <summary>
/// Notify a message to the log. In debug mode the message will also be logged
/// to the <paramref name="logLevel"/> list.
/// </summary>
/// <param name="message">Message to log</param>
/// <param name="logLevel">Loglevel for debugging</param>
public static void Notify(string message, RTLogLevel logLevel = RTLogLevel.LVL1)
{
UnityEngine.Debug.Log("RemoteTech: " + message);
#region ON-DEBUGMODE
#if DEBUG
NotifyToLogLevel(message, logLevel);
#endif
#endregion
}
/// <summary>
/// Notify a message to the log. Replaces each format item on the <paramref name="message"/>
/// with the text equivalent of a corresponding objects value from <paramref name="param"/>.
/// </summary>
/// <param name="message">Message to log with format items</param>
/// <param name="param">objects to format</param>
public static void Notify(string message, params object[] param)
{
Notify(string.Format(message, param), RTLogLevel.LVL1);
}
/// <summary>
/// Notify a message to the log. Replaces each format item on the <paramref name="message"/>
/// with the text equivalent of a corresponding objects value from <paramref name="param"/>.
/// In debug mode the message will also be logged to the <paramref name="logLevel"/> list.
/// </summary>
/// <param name="message">Message to log with format items</param>
/// <param name="logLevel">Loglevel for debugging</param>
/// <param name="param">objects to format</param>
public static void Notify(string message, RTLogLevel logLevel = RTLogLevel.LVL1, params object[] param)
{
Notify(string.Format(message, param), logLevel);
}
/// <summary>
/// Notify a message to the log only if the VERBOSE_DEBUG_LOG from the ksp settings.cfg
/// is set to true. In debug mode the message will also be logged to the
/// <paramref name="logLevel"/> list.
/// </summary>
/// <param name="message">Message to log</param>
/// <param name="logLevel">Loglevel for debugging</param>
public static void Verbose(string message, RTLogLevel logLevel = RTLogLevel.LVL1)
{
if (verboseLogging)
{
Notify(message, logLevel);
}
}
/// <summary>
/// Notify a message to the log only if the VERBOSE_DEBUG_LOG from the ksp settings.cfg
/// is set to true. Replaces each format item on the <paramref name="message"/>
/// with the text equivalent of a corresponding objects value from <paramref name="param"/>.
/// In debug mode the message will also be logged to the <paramref name="logLevel"/> list.
/// </summary>
/// <param name="message">Message to log</param>
/// <param name="logLevel">Loglevel for debugging</param>
/// <param name="param">objects to format</param>
public static void Verbose(string message, RTLogLevel logLevel = RTLogLevel.LVL1, params object[] param)
{
Verbose(string.Format(message, param), logLevel);
}
/// <summary>
/// Logs the <paramref name="message"/> to the <paramref name="logLevel"/>
/// </summary>
/// <param name="message">Message to log</param>
/// <param name="logLevel">Loglevel for debugging</param>
private static void NotifyToLogLevel(string message, RTLogLevel logLevel)
{
RTLogList[logLevel].Add(message);
}
}
public static class RTLogExtenstions
{
public static string ToDebugString<T>(this List<T> list)
{
return "{" + string.Join(",", list.Select(x => x.ToString()).ToArray()) + "}";
}
}
}