From 2a0c09127c96bd549056e576f45cfdf20c5c64f6 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Sat, 4 Aug 2018 18:25:37 -0500 Subject: [PATCH] Made the standard logger able to show the caller --- IllusionInjector/Logging/StandardLogger.cs | 12 ++++++++++++ IllusionPlugin/Logging/Logger.cs | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/IllusionInjector/Logging/StandardLogger.cs b/IllusionInjector/Logging/StandardLogger.cs index 5df62bfe..40e347db 100644 --- a/IllusionInjector/Logging/StandardLogger.cs +++ b/IllusionInjector/Logging/StandardLogger.cs @@ -4,6 +4,7 @@ using IllusionPlugin.Logging; using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; @@ -60,6 +61,7 @@ namespace IllusionInjector.Logging private string logName; private static LogLevel showFilter = LogLevel.InfoUp; + private static bool showSourceClass = true; public static LogLevel PrintFilter { get => showFilter; set => showFilter = value; } private List printers = new List(defaultPrinters); @@ -67,6 +69,7 @@ namespace IllusionInjector.Logging { if (ModPrefs.GetBool("IPA", "PrintDebug", false, true)) showFilter = LogLevel.All; + showSourceClass = ModPrefs.GetBool("IPA", "DebugShowCallSource", false, true); } internal StandardLogger(string name) @@ -93,6 +96,15 @@ namespace IllusionInjector.Logging }); } + public override void Debug(string message) + { // add source to message + var stfm = new StackTrace().GetFrame(1).GetMethod(); + if (showSourceClass) + base.Debug($"{{{stfm.DeclaringType.FullName}::{stfm.Name}}} {message}"); + else + base.Debug(message); + } + internal struct LogMessage { public Level level; diff --git a/IllusionPlugin/Logging/Logger.cs b/IllusionPlugin/Logging/Logger.cs index 210d0960..befa4ccd 100644 --- a/IllusionPlugin/Logging/Logger.cs +++ b/IllusionPlugin/Logging/Logger.cs @@ -107,76 +107,76 @@ namespace IllusionPlugin.Logging /// /// the level of the message /// the exception to log - public void Log(Level level, Exception exeption) => Log(level, exeption.ToString()); + public virtual 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); + public virtual 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); + public virtual 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); + public virtual 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); + public virtual 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); + public virtual 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); + public virtual 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); + public virtual 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); + public virtual 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); + public virtual 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); + public virtual void Critical(Exception e) => Log(Level.Critical, e); } }