-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loggers.cs
98 lines (80 loc) · 2.75 KB
/
Loggers.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
#pragma warning disable CS0162
using System;
using UnityDebug = UnityEngine.Debug;
using QudDebug = global::Logger;
using static HarmonyInjector.Constants;
namespace HarmonyInjector
{
/// <summary>
/// The debug logger for game-mode.
/// </summary>
public static class GameLog
{
/// <summary>
/// Logs an informational message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Info(string message)
{
if (UseNewLogging) QudDebug.gameLog.Info(Format(message));
else UnityDebug.Log(Format(message, "Info"));
}
/// <summary>
/// Logs an error message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Error(string message)
{
if (UseNewLogging) QudDebug.gameLog.Error(Format(message));
else UnityDebug.LogError(Format(message, "Error"));
}
/// <summary>
/// Logs an exception as an error.
/// </summary>
/// <param name="exception">The exception to log.</param>
public static void Error(Exception exception)
{
Error(exception.ToLogMessage());
}
private static string Format(object message) =>
$"[{ModID}] {message}";
private static string Format(object message, string level) =>
$"[{ModID}::Game {level}] {message}";
}
/// <summary>
/// The debug logger for mod-compilation.
/// </summary>
public static class BuildLog
{
/// <summary>
/// Logs an informational message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Info(string message)
{
if (UseNewLogging) QudDebug.buildLog.Info(Format(message));
else UnityDebug.Log(Format(message, "Info"));
}
/// <summary>
/// Logs an error message.
/// </summary>
/// <param name="message">The message to log.</param>
public static void Error(string message)
{
if (UseNewLogging) QudDebug.buildLog.Error(Format(message));
else UnityDebug.LogError(Format(message, "Error"));
}
/// <summary>
/// Logs an exception as an error.
/// </summary>
/// <param name="exception">The exception to log.</param>
public static void Error(Exception exception)
{
Error(exception.ToLogMessage());
}
private static string Format(object message) =>
$"[{ModID}] {message}";
private static string Format(object message, string level) =>
$"[{ModID}::Build {level}] {message}";
}
}