Browse Source

Made the standard logger able to show the caller

pull/46/head
Anairkoen Schno 6 years ago
parent
commit
2a0c09127c
2 changed files with 23 additions and 11 deletions
  1. +12
    -0
      IllusionInjector/Logging/StandardLogger.cs
  2. +11
    -11
      IllusionPlugin/Logging/Logger.cs

+ 12
- 0
IllusionInjector/Logging/StandardLogger.cs View File

@ -4,6 +4,7 @@ using IllusionPlugin.Logging;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -60,6 +61,7 @@ namespace IllusionInjector.Logging
private string logName; private string logName;
private static LogLevel showFilter = LogLevel.InfoUp; private static LogLevel showFilter = LogLevel.InfoUp;
private static bool showSourceClass = true;
public static LogLevel PrintFilter { get => showFilter; set => showFilter = value; } public static LogLevel PrintFilter { get => showFilter; set => showFilter = value; }
private List<LogPrinter> printers = new List<LogPrinter>(defaultPrinters); private List<LogPrinter> printers = new List<LogPrinter>(defaultPrinters);
@ -67,6 +69,7 @@ namespace IllusionInjector.Logging
{ {
if (ModPrefs.GetBool("IPA", "PrintDebug", false, true)) if (ModPrefs.GetBool("IPA", "PrintDebug", false, true))
showFilter = LogLevel.All; showFilter = LogLevel.All;
showSourceClass = ModPrefs.GetBool("IPA", "DebugShowCallSource", false, true);
} }
internal StandardLogger(string name) 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 internal struct LogMessage
{ {
public Level level; public Level level;


+ 11
- 11
IllusionPlugin/Logging/Logger.cs View File

@ -107,76 +107,76 @@ namespace IllusionPlugin.Logging
/// </summary> /// </summary>
/// <param name="level">the level of the message</param> /// <param name="level">the level of the message</param>
/// <param name="exeption">the exception to log</param> /// <param name="exeption">the exception to log</param>
public void Log(Level level, Exception exeption) => Log(level, exeption.ToString());
public virtual void Log(Level level, Exception exeption) => Log(level, exeption.ToString());
/// <summary> /// <summary>
/// Sends a debug message. /// Sends a debug message.
/// Equivalent to Log(Level.Debug, message); /// Equivalent to Log(Level.Debug, message);
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public void Debug(string message) => Log(Level.Debug, message);
public virtual void Debug(string message) => Log(Level.Debug, message);
/// <summary> /// <summary>
/// Sends an exception as a debug message. /// Sends an exception as a debug message.
/// Equivalent to Log(Level.Debug, e); /// Equivalent to Log(Level.Debug, e);
/// <see cref="Log(Level, Exception)"/> /// <see cref="Log(Level, Exception)"/>
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public void Debug(Exception e) => Log(Level.Debug, e);
public virtual void Debug(Exception e) => Log(Level.Debug, e);
/// <summary> /// <summary>
/// Sends an info message. /// Sends an info message.
/// Equivalent to Log(Level.Info, message). /// Equivalent to Log(Level.Info, message).
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public void Info(string message) => Log(Level.Info, message);
public virtual void Info(string message) => Log(Level.Info, message);
/// <summary> /// <summary>
/// Sends an exception as an info message. /// Sends an exception as an info message.
/// Equivalent to Log(Level.Info, e); /// Equivalent to Log(Level.Info, e);
/// <see cref="Log(Level, Exception)"/> /// <see cref="Log(Level, Exception)"/>
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public void Info(Exception e) => Log(Level.Info, e);
public virtual void Info(Exception e) => Log(Level.Info, e);
/// <summary> /// <summary>
/// Sends a warning message. /// Sends a warning message.
/// Equivalent to Log(Level.Warning, message). /// Equivalent to Log(Level.Warning, message).
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public void Warn(string message) => Log(Level.Warning, message);
public virtual void Warn(string message) => Log(Level.Warning, message);
/// <summary> /// <summary>
/// Sends an exception as a warning message. /// Sends an exception as a warning message.
/// Equivalent to Log(Level.Warning, e); /// Equivalent to Log(Level.Warning, e);
/// <see cref="Log(Level, Exception)"/> /// <see cref="Log(Level, Exception)"/>
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public void Warn(Exception e) => Log(Level.Warning, e);
public virtual void Warn(Exception e) => Log(Level.Warning, e);
/// <summary> /// <summary>
/// Sends an error message. /// Sends an error message.
/// Equivalent to Log(Level.Error, message). /// Equivalent to Log(Level.Error, message).
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public void Error(string message) => Log(Level.Error, message);
public virtual void Error(string message) => Log(Level.Error, message);
/// <summary> /// <summary>
/// Sends an exception as an error message. /// Sends an exception as an error message.
/// Equivalent to Log(Level.Error, e); /// Equivalent to Log(Level.Error, e);
/// <see cref="Log(Level, Exception)"/> /// <see cref="Log(Level, Exception)"/>
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public void Error(Exception e) => Log(Level.Error, e);
public virtual void Error(Exception e) => Log(Level.Error, e);
/// <summary> /// <summary>
/// Sends a critical message. /// Sends a critical message.
/// Equivalent to Log(Level.Critical, message). /// Equivalent to Log(Level.Critical, message).
/// <see cref="Log(Level, string)"/> /// <see cref="Log(Level, string)"/>
/// </summary> /// </summary>
/// <param name="message">the message to log</param> /// <param name="message">the message to log</param>
public void Critical(string message) => Log(Level.Critical, message);
public virtual void Critical(string message) => Log(Level.Critical, message);
/// <summary> /// <summary>
/// Sends an exception as a critical message. /// Sends an exception as a critical message.
/// Equivalent to Log(Level.Critical, e); /// Equivalent to Log(Level.Critical, e);
/// <see cref="Log(Level, Exception)"/> /// <see cref="Log(Level, Exception)"/>
/// </summary> /// </summary>
/// <param name="e">the exception to log</param> /// <param name="e">the exception to log</param>
public void Critical(Exception e) => Log(Level.Critical, e);
public virtual void Critical(Exception e) => Log(Level.Critical, e);
} }
} }

Loading…
Cancel
Save