From d57eba7f631d36ba6cd379dbbadf1715c4b0386c Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Fri, 10 Feb 2023 22:36:34 -0800 Subject: [PATCH 1/2] feat: Add LogRaw to PluginLog Adds the ability to send a log message to Serilog specifying a log level at runtime. This feature is primarily aimed at allowing developers to easily bridge disparate logging systems without hardcoding log level calls. --- Dalamud/Logging/PluginLog.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Dalamud/Logging/PluginLog.cs b/Dalamud/Logging/PluginLog.cs index a5aad330f..80edbe430 100644 --- a/Dalamud/Logging/PluginLog.cs +++ b/Dalamud/Logging/PluginLog.cs @@ -240,6 +240,20 @@ public static class PluginLog #endregion + /// + /// Log a message to the in-game log, setting level at runtime. + /// + /// + /// This method is primarily meant for interoperability with other logging systems that may want to be forwarded to + /// the PluginLog. + /// + /// The log level for this message. + /// An exception (if any) to include in this log message. + /// The message template. + /// Values to log. + public static void LogRaw(LogEventLevel level, Exception? exception, string messageTemplate, params object[] values) + => WriteLog(Assembly.GetCallingAssembly().GetName().Name, level, messageTemplate, exception, values); + private static ILogger GetPluginLogger(string? pluginName) { return Serilog.Log.ForContext("SourceContext", pluginName ?? string.Empty); From 4f3727c78b8aa51bf340670e8d07a41ac70ce1c8 Mon Sep 17 00:00:00 2001 From: Kaz Wolfe Date: Fri, 10 Feb 2023 22:37:33 -0800 Subject: [PATCH 2/2] chore: Convert Exception to nullable in PluginLog Allows specifying Exception as a nullable parameter to various Log calls where an Exception may or may not be present in the caller. --- Dalamud/Logging/PluginLog.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Dalamud/Logging/PluginLog.cs b/Dalamud/Logging/PluginLog.cs index 80edbe430..b2f2a5065 100644 --- a/Dalamud/Logging/PluginLog.cs +++ b/Dalamud/Logging/PluginLog.cs @@ -27,7 +27,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void Log(Exception exception, string messageTemplate, params object[] values) + public static void Log(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values); /// @@ -44,7 +44,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void LogVerbose(Exception exception, string messageTemplate, params object[] values) + public static void LogVerbose(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, exception, values); /// @@ -61,7 +61,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void LogDebug(Exception exception, string messageTemplate, params object[] values) + public static void LogDebug(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, exception, values); /// @@ -78,7 +78,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void LogInformation(Exception exception, string messageTemplate, params object[] values) + public static void LogInformation(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values); /// @@ -95,7 +95,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void LogWarning(Exception exception, string messageTemplate, params object[] values) + public static void LogWarning(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, exception, values); /// @@ -112,7 +112,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void LogError(Exception exception, string messageTemplate, params object[] values) + public static void LogError(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, exception, values); /// @@ -129,7 +129,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void LogFatal(Exception exception, string messageTemplate, params object[] values) + public static void LogFatal(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, exception, values); #endregion @@ -150,7 +150,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void Verbose(Exception exception, string messageTemplate, params object[] values) + public static void Verbose(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Verbose, messageTemplate, exception, values); /// @@ -167,7 +167,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void Debug(Exception exception, string messageTemplate, params object[] values) + public static void Debug(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Debug, messageTemplate, exception, values); /// @@ -184,7 +184,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void Information(Exception exception, string messageTemplate, params object[] values) + public static void Information(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Information, messageTemplate, exception, values); /// @@ -201,7 +201,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void Warning(Exception exception, string messageTemplate, params object[] values) + public static void Warning(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Warning, messageTemplate, exception, values); /// @@ -218,7 +218,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void Error(Exception exception, string messageTemplate, params object[] values) + public static void Error(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Error, messageTemplate, exception, values); /// @@ -235,7 +235,7 @@ public static class PluginLog /// The exception that caused the error. /// The message template. /// Values to log. - public static void Fatal(Exception exception, string messageTemplate, params object[] values) + public static void Fatal(Exception? exception, string messageTemplate, params object[] values) => WriteLog(Assembly.GetCallingAssembly().GetName().Name, LogEventLevel.Fatal, messageTemplate, exception, values); #endregion