mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-19 06:17:43 +01:00
Migrate files to Dalamud.Logging namespace Remove Log.LogX methods.
This commit is contained in:
parent
6c56260f45
commit
8fd119dde8
16 changed files with 128 additions and 252 deletions
124
Dalamud/Logging/Internal/ModuleLog.cs
Normal file
124
Dalamud/Logging/Internal/ModuleLog.cs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
using System;
|
||||
|
||||
namespace Dalamud.Logging.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Class offering various methods to allow for logging in Dalamud modules.
|
||||
/// </summary>
|
||||
internal class ModuleLog
|
||||
{
|
||||
private readonly string moduleName;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ModuleLog"/> class.
|
||||
/// This class can be used to prefix logging messages with a Dalamud module name prefix. For example, "[PLUGINR] ...".
|
||||
/// </summary>
|
||||
/// <param name="moduleName">The module name.</param>
|
||||
public ModuleLog(string moduleName)
|
||||
{
|
||||
this.moduleName = moduleName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Verbose(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Verbose($"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Verbose(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Verbose(exception, $"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Debug(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Debug($"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Debug(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Debug(exception, $"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Information(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Information($"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Information(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Information(exception, $"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Warning(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Warning($"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Warning(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Warning(exception, $"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Error(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Error($"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Error(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Error(exception, $"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Fatal(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Fatal($"[{this.moduleName}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public void Fatal(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Fatal(exception, $"[{this.moduleName}] {messageTemplate}", values);
|
||||
}
|
||||
}
|
||||
51
Dalamud/Logging/Internal/SerilogEventSink.cs
Normal file
51
Dalamud/Logging/Internal/SerilogEventSink.cs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
|
||||
using Serilog.Core;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace Dalamud.Logging.Internal
|
||||
{
|
||||
/// <summary>
|
||||
/// Serilog event sink.
|
||||
/// </summary>
|
||||
internal class SerilogEventSink : ILogEventSink
|
||||
{
|
||||
private static SerilogEventSink instance;
|
||||
private readonly IFormatProvider formatProvider;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SerilogEventSink"/> class.
|
||||
/// </summary>
|
||||
/// <param name="formatProvider">Logging format provider.</param>
|
||||
private SerilogEventSink(IFormatProvider formatProvider)
|
||||
{
|
||||
this.formatProvider = formatProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event on a log line being emitted.
|
||||
/// </summary>
|
||||
public event EventHandler<(string Line, LogEventLevel Level, DateTimeOffset TimeStamp)> OnLogLine;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default instance.
|
||||
/// </summary>
|
||||
public static SerilogEventSink Instance => instance ??= new SerilogEventSink(null);
|
||||
|
||||
/// <summary>
|
||||
/// Emit a log event.
|
||||
/// </summary>
|
||||
/// <param name="logEvent">Log event to be emitted.</param>
|
||||
public void Emit(LogEvent logEvent)
|
||||
{
|
||||
var message = logEvent.RenderMessage(this.formatProvider);
|
||||
|
||||
if (logEvent.Exception != null)
|
||||
{
|
||||
message += "\n" + logEvent.Exception;
|
||||
}
|
||||
|
||||
this.OnLogLine?.Invoke(this, (message, logEvent.Level, logEvent.Timestamp));
|
||||
}
|
||||
}
|
||||
}
|
||||
113
Dalamud/Logging/PluginLog.cs
Normal file
113
Dalamud/Logging/PluginLog.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Dalamud.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Class offering various static methods to allow for logging in plugins.
|
||||
/// </summary>
|
||||
public static class PluginLog
|
||||
{
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Verbose(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Verbose($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated verbose message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Verbose(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Verbose(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Debug(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Debug($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated debug message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Debug(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Debug(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Information(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Information($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated information message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Information(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Information(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Warning(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Warning($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated warning message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Warning(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Warning(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Error(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Error($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated error message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Error(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Error(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Fatal(string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Fatal($"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
|
||||
/// <summary>
|
||||
/// Log a templated fatal message to the in-game debug log.
|
||||
/// </summary>
|
||||
/// <param name="exception">The exception that caused the error.</param>
|
||||
/// <param name="messageTemplate">The message template.</param>
|
||||
/// <param name="values">Values to log.</param>
|
||||
public static void Fatal(Exception exception, string messageTemplate, params object[] values)
|
||||
=> Serilog.Log.Fatal(exception, $"[{Assembly.GetCallingAssembly().GetName().Name}] {messageTemplate}", values);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue