1
- using System ;
1
+ using HarmonyLib ;
2
+ using System ;
2
3
using System . Diagnostics ;
3
4
using System . IO ;
5
+ using UnityEngine ;
6
+
4
7
5
8
public static class Logger
6
9
{
@@ -29,6 +32,7 @@ private static string GetCallingClass()
29
32
return null ;
30
33
}
31
34
35
+
32
36
/// <summary>
33
37
/// Initializes the console.
34
38
///
@@ -58,6 +62,9 @@ internal static void InitLogger()
58
62
Console . SetOut ( sw ) ;
59
63
60
64
65
+ Application . logMessageReceived += HandleUnityLogs ;
66
+
67
+
61
68
Logger . Log ( "Log test" ) ;
62
69
Logger . Warning ( "Warn test" ) ;
63
70
Logger . Error ( "Error test" ) ;
@@ -67,13 +74,55 @@ internal static void InitLogger()
67
74
Logger . Log ( "Logging initialized." ) ;
68
75
69
76
}
77
+ private static string PrevMSG = "" ;
78
+ private static void HandleUnityLogs ( string condition , string stackTrace , LogType type )
79
+ {
80
+ if ( condition == PrevMSG )
81
+ {
82
+ return ;
83
+ }
84
+ switch ( type )
85
+ {
86
+ case LogType . Error :
87
+ Logger . Error ( condition , true ) ;
88
+ Logger . Error ( stackTrace , true ) ;
89
+ break ;
90
+ case LogType . Warning :
91
+ Logger . Warning ( condition , true ) ;
92
+ break ;
93
+ case LogType . Log :
94
+ Logger . Log ( condition , true ) ;
95
+ break ;
96
+ case LogType . Exception :
97
+ Logger . Error ( condition , true ) ;
98
+ Logger . Error ( stackTrace , true ) ;
99
+ break ;
100
+ case LogType . Assert :
101
+ Logger . Error ( condition , true ) ;
102
+ Logger . Error ( stackTrace , true ) ;
103
+ break ;
104
+ }
105
+ }
106
+
70
107
71
108
/// <summary>
72
109
/// Logs into console and output_log.txt
73
110
/// </summary>
74
- public static void Log ( string message )
111
+ public static void Log ( string message , bool doublestack = false )
75
112
{
76
- string formattedString = $ "[INFO : { GetCallingClass ( ) } ] { message } ";
113
+ string formattedString ;
114
+ if ( doublestack )
115
+ {
116
+
117
+ formattedString = $ "[INFO : Unity] { message } ";
118
+ }
119
+ else
120
+ {
121
+ formattedString = $ "[INFO : { GetCallingClass ( ) } ] { message } ";
122
+ }
123
+ //string formattedString = $"[INFO : {GetCallingClass()}] {message}";
124
+
125
+ PrevMSG = formattedString ;
77
126
78
127
Console . ForegroundColor = ConsoleColor . Gray ;
79
128
@@ -84,9 +133,20 @@ public static void Log(string message)
84
133
/// <summary>
85
134
/// Logs a warning into console and logs to output_log.txt
86
135
/// </summary>
87
- public static void Warning ( string message )
136
+ public static void Warning ( string message , bool doublestack = false )
88
137
{
89
- string formattedString = $ "[WARNING : { GetCallingClass ( ) } ] { message } ";
138
+ string formattedString ;
139
+ if ( doublestack )
140
+ {
141
+
142
+ formattedString = $ "[WARNING : Unity] { message } ";
143
+ }
144
+ else
145
+ {
146
+ formattedString = $ "[WARNING : { GetCallingClass ( ) } ] { message } ";
147
+ }
148
+
149
+ PrevMSG = formattedString ;
90
150
91
151
Console . ForegroundColor = ConsoleColor . Yellow ;
92
152
@@ -99,9 +159,21 @@ public static void Warning(string message)
99
159
/// <summary>
100
160
/// Logs an error into console and logs to output_log.txt
101
161
/// </summary>
102
- public static void Error ( string message )
162
+ public static void Error ( string message , bool doublestack = false )
103
163
{
104
- string formattedString = $ "[ERROR : { GetCallingClass ( ) } ] { message } ";
164
+ string formattedString ;
165
+ if ( doublestack )
166
+ {
167
+
168
+ formattedString = $ "[ERROR : Unity] { message } ";
169
+ }
170
+ else
171
+ {
172
+ formattedString = $ "[ERROR : { GetCallingClass ( ) } ] { message } ";
173
+ }
174
+ //string formattedString = $"[ERROR : {GetCallingClass()}] {message}";
175
+
176
+ PrevMSG = formattedString ;
105
177
106
178
Console . ForegroundColor = ConsoleColor . Red ;
107
179
@@ -116,13 +188,25 @@ public static void Error(string message)
116
188
///
117
189
/// <c> VERBOSE LOGGING NEEDS TO BE ENABLED </c>
118
190
/// </summary>
119
- public static void Debug ( string message )
191
+ public static void Debug ( string message , bool doublestack = false )
120
192
{
121
193
if ( ! Splotch . Config . LoadedSplotchConfig . verboseLoggingEnabled )
122
194
{
123
195
return ;
124
196
}
125
- string formattedString = $ "[DEBUG : { GetCallingClass ( ) } ] { message } ";
197
+
198
+ string formattedString ;
199
+ if ( doublestack )
200
+ {
201
+
202
+ formattedString = $ "[DEBUG : Unity] { message } ";
203
+ }
204
+ else
205
+ {
206
+ formattedString = $ "[DEBUG : { GetCallingClass ( ) } ] { message } ";
207
+ }
208
+
209
+ PrevMSG = formattedString ;
126
210
127
211
Console . ForegroundColor = ConsoleColor . White ;
128
212
0 commit comments