Fix log filtering with IPluginLog

- Rename `PluginLog`'s property to `Dalamud.PluginName` to match what `IPluginLog` is doing.
- Change `ModuleLog` to use `Dalamud.ModuleName` as its context property.
- Update the Console window to handle both changes.
  - Add the ability to filter to only Dalamud module log messages.
This commit is contained in:
Kaz Wolfe 2023-09-09 15:10:52 -07:00
parent 40b875c8e9
commit 764e0a81b7
No known key found for this signature in database
GPG key ID: 258813F53A16EBB4
3 changed files with 31 additions and 16 deletions

View file

@ -12,6 +12,10 @@ public class ModuleLog
{
private readonly string moduleName;
private readonly ILogger moduleLogger;
// FIXME (v9): Deprecate this class in favor of using contextualized ILoggers with proper formatting.
// We can keep this class around as a Serilog helper, but ModuleLog should no longer be a returned
// type, instead returning a (prepared) ILogger appropriately.
/// <summary>
/// Initializes a new instance of the <see cref="ModuleLog"/> class.
@ -20,10 +24,8 @@ public class ModuleLog
/// <param name="moduleName">The module name.</param>
public ModuleLog(string? moduleName)
{
// FIXME: Should be namespaced better, e.g. `Dalamud.PluginLoader`, but that becomes a relatively large
// change.
this.moduleName = moduleName ?? "DalamudInternal";
this.moduleLogger = Log.ForContext("SourceContext", this.moduleName);
this.moduleLogger = Log.ForContext("Dalamud.ModuleName", this.moduleName);
}
/// <summary>
@ -128,7 +130,8 @@ public class ModuleLog
public void Fatal(Exception exception, string messageTemplate, params object[] values)
=> this.WriteLog(LogEventLevel.Fatal, messageTemplate, exception, values);
private void WriteLog(LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values)
private void WriteLog(
LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values)
{
// FIXME: Eventually, the `pluginName` tag should be removed from here and moved over to the actual log
// formatter.