diff --git a/IllusionInjector/Bootstrapper.cs b/IllusionInjector/Bootstrapper.cs
index f84bbe73..8af36da4 100644
--- a/IllusionInjector/Bootstrapper.cs
+++ b/IllusionInjector/Bootstrapper.cs
@@ -1,4 +1,5 @@
-using System;
+using IllusionInjector.Logging;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -16,6 +17,13 @@ namespace IllusionInjector
{
Windows.GuiConsole.CreateConsole();
}
+
+ Application.logMessageReceived += delegate (string condition, string stackTrace, LogType type)
+ {
+ var level = UnityLogInterceptor.LogTypeToLevel(type);
+ UnityLogInterceptor.Unitylogger.Log(level, $"{condition.Trim()}");
+ UnityLogInterceptor.Unitylogger.Log(level, $"{stackTrace.Trim()}");
+ };
}
void Start()
diff --git a/IllusionInjector/IllusionInjector.csproj b/IllusionInjector/IllusionInjector.csproj
index a8a56c31..48a39058 100644
--- a/IllusionInjector/IllusionInjector.csproj
+++ b/IllusionInjector/IllusionInjector.csproj
@@ -59,6 +59,7 @@
+
diff --git a/IllusionInjector/Logging/UnityLogInterceptor.cs b/IllusionInjector/Logging/UnityLogInterceptor.cs
new file mode 100644
index 00000000..64e42926
--- /dev/null
+++ b/IllusionInjector/Logging/UnityLogInterceptor.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using UnityEngine;
+using LoggerBase = IllusionPlugin.Logging.Logger;
+
+namespace IllusionInjector.Logging
+{
+ public class UnityLogInterceptor
+ {
+ public static LoggerBase Unitylogger = new StandardLogger("UnityEngine");
+
+ public static LoggerBase.Level LogTypeToLevel(LogType type)
+ {
+ switch (type)
+ {
+ case LogType.Assert:
+ return LoggerBase.Level.Debug;
+ case LogType.Error:
+ return LoggerBase.Level.Error;
+ case LogType.Exception:
+ return LoggerBase.Level.Critical;
+ case LogType.Log:
+ return LoggerBase.Level.Info;
+ case LogType.Warning:
+ return LoggerBase.Level.Warning;
+ default:
+ return LoggerBase.Level.Info;
+ }
+ }
+ }
+}
diff --git a/IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache b/IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache
index 19ffd47d..320879d5 100644
--- a/IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache
+++ b/IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache
@@ -1 +1 @@
-524c2a9e58911edfdaf36eb5bf255b181a39f814
+8c1883c8697a3dc7189ee9ff1c9d85d453a46fe5
diff --git a/IllusionPlugin/Logging/LogPrinter.cs b/IllusionPlugin/Logging/LogPrinter.cs
index d5c6b943..441029e6 100644
--- a/IllusionPlugin/Logging/LogPrinter.cs
+++ b/IllusionPlugin/Logging/LogPrinter.cs
@@ -6,11 +6,32 @@ using System.Threading.Tasks;
namespace IllusionPlugin.Logging
{
+ ///
+ /// The log printer's base class.
+ ///
public abstract class LogPrinter
{
+ ///
+ /// Provides a filter for which log levels to allow through.
+ ///
public abstract Logger.LogLevel Filter { get; set; }
+ ///
+ /// Prints a provided message from a given log at the specified time.
+ ///
+ /// the log level
+ /// the time the message was composed
+ /// the name of the log that created this message
+ /// the message
public abstract void Print(Logger.Level level, DateTime time, string logName, string message);
+ ///
+ /// Called before the first print in a group. May be called multiple times.
+ /// Use this to create file handles and the like.
+ ///
public virtual void StartPrint() { }
+ ///
+ /// Called after the last print in a group. May be called multiple times.
+ /// Use this to dispose file handles and the like.
+ ///
public virtual void EndPrint() { }
}
}
diff --git a/IllusionPlugin/Logging/Logger.cs b/IllusionPlugin/Logging/Logger.cs
index 796d399c..210d0960 100644
--- a/IllusionPlugin/Logging/Logger.cs
+++ b/IllusionPlugin/Logging/Logger.cs
@@ -6,47 +6,177 @@ using System.Threading.Tasks;
namespace IllusionPlugin.Logging
{
+ ///
+ /// The logger base class. Provides the format for console logs.
+ ///
public abstract class Logger
{
+ ///
+ /// The standard format for log messages.
+ ///
public static string LogFormat { get; protected internal set; } = "[{3} @ {2:HH:mm:ss} | {1}] {0}";
+ ///
+ /// An enum specifying the level of the message. Resembles Syslog.
+ ///
public enum Level : byte
{
+ ///
+ /// No associated level. These never get shown.
+ ///
None = 0,
+ ///
+ /// A debug message.
+ ///
Debug = 1,
+ ///
+ /// An informational message.
+ ///
Info = 2,
+ ///
+ /// A warning message.
+ ///
Warning = 4,
+ ///
+ /// An error message.
+ ///
Error = 8,
+ ///
+ /// A critical error message.
+ ///
Critical = 16
}
+ ///
+ /// An enum providing log level filters.
+ ///
[Flags]
public enum LogLevel : byte
{
+ ///
+ /// Allow no messages through.
+ ///
None = Level.None,
+ ///
+ /// Only shows Debug messages.
+ ///
DebugOnly = Level.Debug,
+ ///
+ /// Only shows info messages.
+ ///
InfoOnly = Level.Info,
+ ///
+ /// Only shows Warning messages.
+ ///
WarningOnly = Level.Warning,
+ ///
+ /// Only shows Error messages.
+ ///
ErrorOnly = Level.Error,
+ ///
+ /// Only shows Critical messages.
+ ///
CriticalOnly = Level.Critical,
+ ///
+ /// Shows all messages error and up.
+ ///
ErrorUp = ErrorOnly | CriticalOnly,
+ ///
+ /// Shows all messages warning and up.
+ ///
WarningUp = WarningOnly | ErrorUp,
+ ///
+ /// Shows all messages info and up.
+ ///
InfoUp = InfoOnly | WarningUp,
+ ///
+ /// Shows all messages.
+ ///
All = DebugOnly | InfoUp,
}
+ ///
+ /// A basic log function.
+ ///
+ /// the level of the message
+ /// the message to log
public abstract void Log(Level level, string message);
+ ///
+ /// A basic log function taking an exception to log.
+ ///
+ /// the level of the message
+ /// the exception to log
public void Log(Level level, Exception exeption) => Log(level, exeption.ToString());
+ ///
+ /// Sends a debug message.
+ /// Equivalent to Log(Level.Debug, message);
+ ///
+ ///
+ /// the message to log
public void Debug(string message) => Log(Level.Debug, message);
+ ///
+ /// Sends an exception as a debug message.
+ /// Equivalent to Log(Level.Debug, e);
+ ///
+ ///
+ /// the exception to log
public void Debug(Exception e) => Log(Level.Debug, e);
+ ///
+ /// Sends an info message.
+ /// Equivalent to Log(Level.Info, message).
+ ///
+ ///
+ /// the message to log
public void Info(string message) => Log(Level.Info, message);
+ ///
+ /// Sends an exception as an info message.
+ /// Equivalent to Log(Level.Info, e);
+ ///
+ ///
+ /// the exception to log
public void Info(Exception e) => Log(Level.Info, e);
+ ///
+ /// Sends a warning message.
+ /// Equivalent to Log(Level.Warning, message).
+ ///
+ ///
+ /// the message to log
public void Warn(string message) => Log(Level.Warning, message);
+ ///
+ /// Sends an exception as a warning message.
+ /// Equivalent to Log(Level.Warning, e);
+ ///
+ ///
+ /// the exception to log
public void Warn(Exception e) => Log(Level.Warning, e);
+ ///
+ /// Sends an error message.
+ /// Equivalent to Log(Level.Error, message).
+ ///
+ ///
+ /// the message to log
public void Error(string message) => Log(Level.Error, message);
+ ///
+ /// Sends an exception as an error message.
+ /// Equivalent to Log(Level.Error, e);
+ ///
+ ///
+ /// the exception to log
public void Error(Exception e) => Log(Level.Error, e);
+ ///
+ /// Sends a critical message.
+ /// Equivalent to Log(Level.Critical, message).
+ ///
+ ///
+ /// the message to log
public void Critical(string message) => Log(Level.Critical, message);
+ ///
+ /// Sends an exception as a critical message.
+ /// Equivalent to Log(Level.Critical, e);
+ ///
+ ///
+ /// the exception to log
public void Critical(Exception e) => Log(Level.Critical, e);
}
}