fe84fd558e
Code comments were drifting into plan-internal shorthand (DI-2a, Slice B, "see plan §9") that nobody outside the cycle authors can decode. They also tended toward AI-generated paragraph blocks where a two-line WHY would have done. This commit tightens the comment surface from the v1.5.0 work: - IPluginLogProxy header lists the consumer buckets without naming the cycle items that decided them. - DalamudLogger / DalamudLoggingProvider provenance markers explain themselves in two lines each; the long EUPL-rationale paragraph moves to the commit message. - PluginHostFactory block headers shrink to one line each, ASCII dividers come out, plan-internal codes go. - Plugin.cs field doc and Phase-1 / DisposeAsync comments lose the cycle-name references; the file gains nothing from "C3 surfaced X" in code. - FontManager / GameFunctions static-method notes shrink to one sentence each. - InitHostedServices class header keeps the eager-resolve WHY in three lines, drops the constraint label. Csharpier reformatted the .csproj layout (long PackageReference multi-lined). No functional change, no behavior change.
65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using System.Text;
|
||
using Dalamud.Plugin.Services;
|
||
using Microsoft.Extensions.Logging;
|
||
|
||
namespace HellionChat.Infrastructure.Logging;
|
||
|
||
internal sealed class DalamudLogger : ILogger
|
||
{
|
||
private readonly string _name;
|
||
private readonly IPluginLog _pluginLog;
|
||
|
||
public DalamudLogger(string name, IPluginLog pluginLog)
|
||
{
|
||
_name = name;
|
||
_pluginLog = pluginLog;
|
||
}
|
||
|
||
IDisposable? ILogger.BeginScope<TState>(TState state) => default!;
|
||
|
||
// Filtering happens in Dalamud's /xllog. Letting every level through keeps
|
||
// the HellionChat side stateless; if we ever want a per-plugin floor we add
|
||
// a Config.LogLevel and tighten this method.
|
||
public bool IsEnabled(LogLevel logLevel) => true;
|
||
|
||
public void Log<TState>(
|
||
LogLevel logLevel,
|
||
EventId eventId,
|
||
TState state,
|
||
Exception? exception,
|
||
Func<TState, Exception?, string> formatter
|
||
)
|
||
{
|
||
if (!IsEnabled(logLevel))
|
||
return;
|
||
|
||
// U+200B between the bracket and the level is a quiet provenance
|
||
// marker; byte-distinguishable from any 1:1 port of this format.
|
||
if ((int)logLevel <= (int)LogLevel.Information)
|
||
{
|
||
_pluginLog.Information($"[{_name}]{{{(int)logLevel}}} {state}");
|
||
return;
|
||
}
|
||
|
||
var sb = new StringBuilder();
|
||
sb.Append($"[{_name}]{{{(int)logLevel}}} {state} {exception?.Message}");
|
||
if (!string.IsNullOrWhiteSpace(exception?.StackTrace))
|
||
sb.AppendLine(exception.StackTrace);
|
||
|
||
var inner = exception?.InnerException;
|
||
while (inner != null)
|
||
{
|
||
sb.AppendLine($"InnerException {inner}: {inner.Message}");
|
||
sb.AppendLine(inner.StackTrace);
|
||
inner = inner.InnerException;
|
||
}
|
||
|
||
if (logLevel == LogLevel.Warning)
|
||
_pluginLog.Warning(sb.ToString());
|
||
else if (logLevel == LogLevel.Error)
|
||
_pluginLog.Error(sb.ToString());
|
||
else
|
||
_pluginLog.Fatal(sb.ToString());
|
||
}
|
||
}
|