This commit is contained in:
rootdarkarchon
2024-03-24 16:40:01 +01:00
parent 73828ce717
commit 59ade9dc0c
7 changed files with 46 additions and 27 deletions

View File

@@ -10,12 +10,14 @@ internal sealed class DalamudLogger : ILogger
private readonly MareConfigService _mareConfigService;
private readonly string _name;
private readonly IPluginLog _pluginLog;
private readonly bool _hasModifiedGameFiles;
public DalamudLogger(string name, MareConfigService mareConfigService, IPluginLog pluginLog)
public DalamudLogger(string name, MareConfigService mareConfigService, IPluginLog pluginLog, bool hasModifiedGameFiles)
{
_name = name;
_mareConfigService = mareConfigService;
_pluginLog = pluginLog;
_hasModifiedGameFiles = hasModifiedGameFiles;
}
public IDisposable BeginScope<TState>(TState state) => default!;
@@ -29,12 +31,14 @@ internal sealed class DalamudLogger : ILogger
{
if (!IsEnabled(logLevel)) return;
string unsupported = _hasModifiedGameFiles ? "[UNSUPPORTED]" : string.Empty;
if ((int)logLevel <= (int)LogLevel.Information)
_pluginLog.Information($"[{_name}]{{{(int)logLevel}}} {state}");
_pluginLog.Information($"{unsupported}[{_name}]{{{(int)logLevel}}} {state}{(_hasModifiedGameFiles ? "." : string.Empty)}");
else
{
StringBuilder sb = new();
sb.AppendLine($"[{_name}]{{{(int)logLevel}}} {state}: {exception?.Message}");
sb.AppendLine($"{unsupported}[{_name}]{{{(int)logLevel}}} {state}{(_hasModifiedGameFiles ? "." : string.Empty)}: {exception?.Message}");
sb.AppendLine(exception?.StackTrace);
var innerException = exception?.InnerException;
while (innerException != null)

View File

@@ -14,11 +14,13 @@ public sealed class DalamudLoggingProvider : ILoggerProvider
private readonly MareConfigService _mareConfigService;
private readonly IPluginLog _pluginLog;
private readonly bool _hasModifiedGameFiles;
public DalamudLoggingProvider(MareConfigService mareConfigService, IPluginLog pluginLog)
public DalamudLoggingProvider(MareConfigService mareConfigService, IPluginLog pluginLog, bool hasModifiedGameFiles)
{
_mareConfigService = mareConfigService;
_pluginLog = pluginLog;
_hasModifiedGameFiles = hasModifiedGameFiles;
}
public ILogger CreateLogger(string categoryName)
@@ -33,7 +35,7 @@ public sealed class DalamudLoggingProvider : ILoggerProvider
catName = string.Join("", Enumerable.Range(0, 15 - catName.Length).Select(_ => " ")) + catName;
}
return _loggers.GetOrAdd(catName, name => new DalamudLogger(name, _mareConfigService, _pluginLog));
return _loggers.GetOrAdd(catName, name => new DalamudLogger(name, _mareConfigService, _pluginLog, _hasModifiedGameFiles));
}
public void Dispose()

View File

@@ -8,12 +8,12 @@ namespace MareSynchronos.Interop;
public static class DalamudLoggingProviderExtensions
{
public static ILoggingBuilder AddDalamudLogging(this ILoggingBuilder builder, IPluginLog pluginLog)
public static ILoggingBuilder AddDalamudLogging(this ILoggingBuilder builder, IPluginLog pluginLog, bool hasModifiedGameFiles)
{
builder.ClearProviders();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, DalamudLoggingProvider>
(b => new DalamudLoggingProvider(b.GetRequiredService<MareConfigService>(), pluginLog)));
(b => new DalamudLoggingProvider(b.GetRequiredService<MareConfigService>(), pluginLog, hasModifiedGameFiles)));
return builder;
}