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)
var pluginInternalNames = Service<PluginManager>.Get().InstalledPlugins
var sourceNames = Service<PluginManager>.Get().InstalledPlugins
.Select(p => p.Manifest.InternalName)
.OrderBy(s => s).ToList();
.OrderBy(s => s)
.Prepend("DalamudInternal")
.ToList();
var sourcePreviewVal = this.sourceFilters.Count switch
{
0 => "All plugins...",
1 => "1 plugin...",
_ => $"{this.sourceFilters.Count} plugins...",
0 => "All sources...",
1 => "1 source...",
_ => $"{this.sourceFilters.Count} sources...",
};
var sourceSelectables = pluginInternalNames.Union(this.sourceFilters).ToList();
if (ImGui.BeginCombo("Plugins", sourcePreviewVal))
var sourceSelectables = sourceNames.Union(this.sourceFilters).ToList();
if (ImGui.BeginCombo("Sources", sourcePreviewVal))
{
foreach (var selectable in sourceSelectables)
{
@ -443,7 +446,8 @@ internal class ConsoleWindow : Window, IDisposable
// TODO: Improve this, add partial completion
// 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)
{
ptr.DeleteChars(0, ptr.BufTextLen);
@ -500,10 +504,16 @@ internal class ConsoleWindow : Window, IDisposable
HasException = logEvent.Exception != null,
};
if (logEvent.Properties.TryGetValue("SourceContext", out var sourceProp) &&
sourceProp is ScalarValue { Value: string value })
// TODO (v9): Remove SourceContext property check.
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);
@ -579,6 +589,10 @@ internal class ConsoleWindow : Window, IDisposable
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 bool HasException { get; set; }

View file

@ -13,6 +13,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.
/// This class can be used to prefix logging messages with a Dalamud module name prefix. For example, "[PLUGINR] ...".
@ -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.

View file

@ -256,7 +256,7 @@ public static class PluginLog
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)