Merge pull request #1377 from KazWolfe/logging-filter-fix

This commit is contained in:
goat 2023-09-17 13:38:55 +02:00 committed by GitHub
commit 7dbd15965a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 17 deletions

View file

@ -180,17 +180,20 @@ internal class ConsoleWindow : Window, IDisposable
} }
// Filter by specific plugin(s) // Filter by specific plugin(s)
var pluginInternalNames = Service<PluginManager>.Get().InstalledPlugins var sourceNames = Service<PluginManager>.Get().InstalledPlugins
.Select(p => p.Manifest.InternalName) .Select(p => p.Manifest.InternalName)
.OrderBy(s => s).ToList(); .OrderBy(s => s)
.Prepend("DalamudInternal")
.ToList();
var sourcePreviewVal = this.sourceFilters.Count switch var sourcePreviewVal = this.sourceFilters.Count switch
{ {
0 => "All plugins...", 0 => "All sources...",
1 => "1 plugin...", 1 => "1 source...",
_ => $"{this.sourceFilters.Count} plugins...", _ => $"{this.sourceFilters.Count} sources...",
}; };
var sourceSelectables = pluginInternalNames.Union(this.sourceFilters).ToList(); var sourceSelectables = sourceNames.Union(this.sourceFilters).ToList();
if (ImGui.BeginCombo("Plugins", sourcePreviewVal)) if (ImGui.BeginCombo("Sources", sourcePreviewVal))
{ {
foreach (var selectable in sourceSelectables) foreach (var selectable in sourceSelectables)
{ {
@ -443,7 +446,8 @@ internal class ConsoleWindow : Window, IDisposable
// TODO: Improve this, add partial completion // TODO: Improve this, add partial completion
// https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp#L6443-L6484 // https://github.com/ocornut/imgui/blob/master/imgui_demo.cpp#L6443-L6484
var candidates = Service<CommandManager>.Get().Commands.Where(x => x.Key.Contains("/" + words[0])).ToList(); var candidates = Service<CommandManager>.Get().Commands.Where(x => x.Key.Contains("/" + words[0]))
.ToList();
if (candidates.Count > 0) if (candidates.Count > 0)
{ {
ptr.DeleteChars(0, ptr.BufTextLen); ptr.DeleteChars(0, ptr.BufTextLen);
@ -499,11 +503,17 @@ internal class ConsoleWindow : Window, IDisposable
TimeStamp = logEvent.Timestamp, TimeStamp = logEvent.Timestamp,
HasException = logEvent.Exception != null, HasException = logEvent.Exception != null,
}; };
if (logEvent.Properties.TryGetValue("SourceContext", out var sourceProp) && // TODO (v9): Remove SourceContext property check.
sourceProp is ScalarValue { Value: string value }) if (logEvent.Properties.ContainsKey("Dalamud.ModuleName"))
{ {
entry.Source = value; entry.Source = "DalamudInternal";
}
else if ((logEvent.Properties.TryGetValue("Dalamud.PluginName", out var sourceProp) ||
logEvent.Properties.TryGetValue("SourceContext", out sourceProp)) &&
sourceProp is ScalarValue { Value: string sourceValue })
{
entry.Source = sourceValue;
} }
this.logText.Add(entry); this.logText.Add(entry);
@ -579,6 +589,10 @@ internal class ConsoleWindow : Window, IDisposable
public bool IsMultiline { get; set; } public bool IsMultiline { get; set; }
/// <summary>
/// Gets or sets the system responsible for generating this log entry. Generally will be a plugin's
/// InternalName.
/// </summary>
public string? Source { get; set; } public string? Source { get; set; }
public bool HasException { get; set; } public bool HasException { get; set; }

View file

@ -12,6 +12,10 @@ public class ModuleLog
{ {
private readonly string moduleName; private readonly string moduleName;
private readonly ILogger moduleLogger; 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> /// <summary>
/// Initializes a new instance of the <see cref="ModuleLog"/> class. /// Initializes a new instance of the <see cref="ModuleLog"/> class.
@ -20,10 +24,8 @@ public class ModuleLog
/// <param name="moduleName">The module name.</param> /// <param name="moduleName">The module name.</param>
public ModuleLog(string? moduleName) 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.moduleName = moduleName ?? "DalamudInternal";
this.moduleLogger = Log.ForContext("SourceContext", this.moduleName); this.moduleLogger = Log.ForContext("Dalamud.ModuleName", this.moduleName);
} }
/// <summary> /// <summary>
@ -128,7 +130,8 @@ public class ModuleLog
public void Fatal(Exception exception, string messageTemplate, params object[] values) public void Fatal(Exception exception, string messageTemplate, params object[] values)
=> this.WriteLog(LogEventLevel.Fatal, messageTemplate, exception, 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 // FIXME: Eventually, the `pluginName` tag should be removed from here and moved over to the actual log
// formatter. // formatter.

View file

@ -256,7 +256,7 @@ public static class PluginLog
private static ILogger GetPluginLogger(string? pluginName) private static ILogger GetPluginLogger(string? pluginName)
{ {
return Serilog.Log.ForContext("SourceContext", pluginName ?? string.Empty); return Serilog.Log.ForContext("Dalamud.PluginName", pluginName ?? string.Empty);
} }
private static void WriteLog(string? pluginName, LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values) private static void WriteLog(string? pluginName, LogEventLevel level, string messageTemplate, Exception? exception = null, params object[] values)