Skip to content
This repository was archived by the owner on Apr 21, 2024. It is now read-only.

Commit 0943b9b

Browse files
authored
Merge pull request #15 from commandblox/dev
v0.1.4
2 parents f7725f0 + 87d67e3 commit 0943b9b

File tree

2 files changed

+94
-10
lines changed

2 files changed

+94
-10
lines changed

Logger.cs

+93-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
using System;
1+
using HarmonyLib;
2+
using System;
23
using System.Diagnostics;
34
using System.IO;
5+
using UnityEngine;
6+
47

58
public static class Logger
69
{
@@ -29,6 +32,7 @@ private static string GetCallingClass()
2932
return null;
3033
}
3134

35+
3236
/// <summary>
3337
/// Initializes the console.
3438
///
@@ -58,6 +62,9 @@ internal static void InitLogger()
5862
Console.SetOut(sw);
5963

6064

65+
Application.logMessageReceived += HandleUnityLogs;
66+
67+
6168
Logger.Log("Log test");
6269
Logger.Warning("Warn test");
6370
Logger.Error("Error test");
@@ -67,13 +74,55 @@ internal static void InitLogger()
6774
Logger.Log("Logging initialized.");
6875

6976
}
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+
70107

71108
/// <summary>
72109
/// Logs into console and output_log.txt
73110
/// </summary>
74-
public static void Log(string message)
111+
public static void Log(string message, bool doublestack = false)
75112
{
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;
77126

78127
Console.ForegroundColor = ConsoleColor.Gray;
79128

@@ -84,9 +133,20 @@ public static void Log(string message)
84133
/// <summary>
85134
/// Logs a warning into console and logs to output_log.txt
86135
/// </summary>
87-
public static void Warning(string message)
136+
public static void Warning(string message, bool doublestack = false)
88137
{
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;
90150

91151
Console.ForegroundColor = ConsoleColor.Yellow;
92152

@@ -99,9 +159,21 @@ public static void Warning(string message)
99159
/// <summary>
100160
/// Logs an error into console and logs to output_log.txt
101161
/// </summary>
102-
public static void Error(string message)
162+
public static void Error(string message, bool doublestack = false)
103163
{
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;
105177

106178
Console.ForegroundColor = ConsoleColor.Red;
107179

@@ -116,13 +188,25 @@ public static void Error(string message)
116188
///
117189
/// <c> VERBOSE LOGGING NEEDS TO BE ENABLED </c>
118190
/// </summary>
119-
public static void Debug(string message)
191+
public static void Debug(string message, bool doublestack = false)
120192
{
121193
if (!Splotch.Config.LoadedSplotchConfig.verboseLoggingEnabled)
122194
{
123195
return;
124196
}
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;
126210

127211
Console.ForegroundColor = ConsoleColor.White;
128212

Properties/AssemblyInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
// X: major versions
3838
// Y: feature addition/ removal
3939
// Z: small patch/ bugfix
40-
[assembly: AssemblyVersion("0.1.3")]
40+
[assembly: AssemblyVersion("0.1.4")]

0 commit comments

Comments
 (0)