refactor(di): migrate Root + Misc to ILogger<T> (DI-4 Slice D)
Slice D shrinks vs the original plan: three of the six files cannot take an ILogger ctor arg without breaking external contracts. Migrated (8 LogProxy sites across 4 files): - Commands: 2 sites (Warning, Error). New ctor takes ILogger<Commands>. - Themes/ThemeRegistry: 1 site (Debug). ILogger<ThemeRegistry>? is optional (default null) so the existing Build-Suite tests that construct `new ThemeRegistry()` parameterless keep working without changes. _logger?.LogDebug guards the call site. - PayloadHandler: 3 sites (Error, Warning, Error). New ctor takes ILogger<PayloadHandler>. ChatLogWindow's two `new PayloadHandler(this)` sites (the direct field and the Lender lambda) now hand a fresh CreateLogger<PayloadHandler>() from the existing _loggerFactory. Not migrated (5 sites stay on Plugin.LogProxy, plan drifts D12-D14): - D12 - Configuration (1 site): IPluginConfiguration, instantiated by Dalamud's Interface.GetPluginConfig() via reflection on the parameterless ctor. Adding an ILogger arg would break GetPluginConfig. - D13 - Message (4 sites): partial data class with two ctor overloads, mass-instantiated across 3 plugin sites plus Newtonsoft JSON deserialisation. Ctor extension would be invasive across ~20 call sites with low payoff (data-class logger is unusual). - D14 - FontManager (2 sites): both Plugin.LogProxy calls live in static methods (TryGetHellionFontBytes, AddFontWithFallback) that cannot reach an instance _logger. Same root cause as D8 in GameFunctions. FontManager joins the static-bucket alongside EmoteCache et al.; the ctor + _logger field added mid-Slice-D were rolled back to keep the class clean. Plugin.LogProxy surface after C9 (8 file buckets, ~12 sites total): - 4 originally-static consumers: EmoteCache, AutoTranslate, MemoryUtil, WrapperUtil - 3 cannot-take-ctor-arg consumers: Configuration, Message, FontManager - 1 single-static-method consumer: GameFunctions.TryOpenAdventurerPlate (D8 from Slice B) Smoke 2 is now due.
This commit is contained in:
@@ -1,10 +1,17 @@
|
|||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace HellionChat;
|
namespace HellionChat;
|
||||||
|
|
||||||
internal sealed class Commands : IDisposable
|
internal sealed class Commands : IDisposable
|
||||||
{
|
{
|
||||||
private readonly Dictionary<string, CommandWrapper> Registered = [];
|
private readonly Dictionary<string, CommandWrapper> Registered = [];
|
||||||
|
private readonly ILogger<Commands> _logger;
|
||||||
|
|
||||||
|
public Commands(ILogger<Commands> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
@@ -52,7 +59,7 @@ internal sealed class Commands : IDisposable
|
|||||||
{
|
{
|
||||||
if (!Registered.TryGetValue(command, out var wrapper))
|
if (!Registered.TryGetValue(command, out var wrapper))
|
||||||
{
|
{
|
||||||
Plugin.LogProxy.Warning($"Missing registration for command {command}");
|
_logger.LogWarning($"Missing registration for command {command}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +69,7 @@ internal sealed class Commands : IDisposable
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Plugin.LogProxy.Error(ex, $"Error while executing command {command}");
|
_logger.LogError(ex, $"Error while executing command {command}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ using Dalamud.Interface.Utility;
|
|||||||
|
|
||||||
namespace HellionChat;
|
namespace HellionChat;
|
||||||
|
|
||||||
|
// FontManager's two LogProxy sites both live in static methods
|
||||||
|
// (TryGetHellionFontBytes, AddFontWithFallback) that the BuildFonts pipeline
|
||||||
|
// invokes; an instance _logger field would be unreachable from those scopes.
|
||||||
|
// DI-4 Slice D leaves the class on Plugin.LogProxy and counts it under the
|
||||||
|
// "static consumers" bucket alongside EmoteCache / AutoTranslate /
|
||||||
|
// MemoryUtil / WrapperUtil.
|
||||||
public class FontManager
|
public class FontManager
|
||||||
{
|
{
|
||||||
internal IFontHandle Axis = null!;
|
internal IFontHandle Axis = null!;
|
||||||
@@ -58,6 +64,9 @@ public class FontManager
|
|||||||
);
|
);
|
||||||
if (stream is null)
|
if (stream is null)
|
||||||
{
|
{
|
||||||
|
// Static method has no instance _logger to reach. The resource-
|
||||||
|
// missing path is rare (only fires when the embedded font is
|
||||||
|
// stripped from the build), so Plugin.LogProxy is acceptable.
|
||||||
Plugin.LogProxy.Warning(
|
Plugin.LogProxy.Warning(
|
||||||
"Hellion font resource missing — falling back to system default font."
|
"Hellion font resource missing — falling back to system default font."
|
||||||
);
|
);
|
||||||
@@ -236,7 +245,9 @@ public class FontManager
|
|||||||
{
|
{
|
||||||
// Atlas-toolkit throws span IO and validation failures; routing the
|
// Atlas-toolkit throws span IO and validation failures; routing the
|
||||||
// wider set through the fallback keeps a corrupt font config from
|
// wider set through the fallback keeps a corrupt font config from
|
||||||
// taking down the whole atlas build.
|
// taking down the whole atlas build. Static method has no instance
|
||||||
|
// _logger to reach (Plugin.Config-driven font swap, called from
|
||||||
|
// BuildFonts).
|
||||||
Plugin.LogProxy.Warning(
|
Plugin.LogProxy.Warning(
|
||||||
e,
|
e,
|
||||||
$"Configured {slot} font failed to load ({e.GetType().Name}), "
|
$"Configured {slot} font failed to load ({e.GetType().Name}), "
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ using HellionChat.Resources;
|
|||||||
using HellionChat.Ui;
|
using HellionChat.Ui;
|
||||||
using HellionChat.Util;
|
using HellionChat.Util;
|
||||||
using Lumina.Excel.Sheets;
|
using Lumina.Excel.Sheets;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Action = System.Action;
|
using Action = System.Action;
|
||||||
using ChatTwoPartyFinderPayload = HellionChat.Util.PartyFinderPayload;
|
using ChatTwoPartyFinderPayload = HellionChat.Util.PartyFinderPayload;
|
||||||
using DalamudPartyFinderPayload = Dalamud.Game.Text.SeStringHandling.Payloads.PartyFinderPayload;
|
using DalamudPartyFinderPayload = Dalamud.Game.Text.SeStringHandling.Payloads.PartyFinderPayload;
|
||||||
@@ -40,9 +41,12 @@ public sealed class PayloadHandler
|
|||||||
|
|
||||||
private const uint PopupSfx = 1;
|
private const uint PopupSfx = 1;
|
||||||
|
|
||||||
internal PayloadHandler(ChatLogWindow logWindow)
|
private readonly ILogger<PayloadHandler> _logger;
|
||||||
|
|
||||||
|
internal PayloadHandler(ChatLogWindow logWindow, ILogger<PayloadHandler> logger)
|
||||||
{
|
{
|
||||||
LogWindow = logWindow;
|
LogWindow = logWindow;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Draw()
|
internal void Draw()
|
||||||
@@ -131,7 +135,7 @@ public sealed class PayloadHandler
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Plugin.LogProxy.Error(ex, "Error executing integration");
|
_logger.LogError(ex, "Error executing integration");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -535,7 +539,7 @@ public sealed class PayloadHandler
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
Plugin.LogProxy.Warning("Could not find DalamudLinkHandlers");
|
_logger.LogWarning("Could not find DalamudLinkHandlers");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,7 +550,7 @@ public sealed class PayloadHandler
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Plugin.LogProxy.Error(ex, "Error executing DalamudLinkPayload handler");
|
_logger.LogError(ex, "Error executing DalamudLinkPayload handler");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ internal static class PluginHostFactory
|
|||||||
sp.GetRequiredService<IPluginLog>()
|
sp.GetRequiredService<IPluginLog>()
|
||||||
));
|
));
|
||||||
services.AddSingleton<FileDialogManager>(_ => new FileDialogManager());
|
services.AddSingleton<FileDialogManager>(_ => new FileDialogManager());
|
||||||
services.AddSingleton(_ => new Commands());
|
services.AddSingleton(sp => new Commands(sp.GetRequiredService<ILogger<Commands>>()));
|
||||||
services.AddSingleton(_ => new FontManager());
|
services.AddSingleton(_ => new FontManager());
|
||||||
services.AddSingleton(_ => new StatusBar());
|
services.AddSingleton(_ => new StatusBar());
|
||||||
services.AddSingleton(sp => new IpcManager(sp.GetRequiredService<ILogger<IpcManager>>()));
|
services.AddSingleton(sp => new IpcManager(sp.GetRequiredService<ILogger<IpcManager>>()));
|
||||||
@@ -107,7 +107,8 @@ internal static class PluginHostFactory
|
|||||||
Path.Combine(
|
Path.Combine(
|
||||||
sp.GetRequiredService<IDalamudPluginInterface>().ConfigDirectory.FullName,
|
sp.GetRequiredService<IDalamudPluginInterface>().ConfigDirectory.FullName,
|
||||||
"themes"
|
"themes"
|
||||||
)
|
),
|
||||||
|
sp.GetRequiredService<ILogger<ThemeRegistry>>()
|
||||||
));
|
));
|
||||||
|
|
||||||
services.AddSingleton(sp => new GameFunctions.GameFunctions(
|
services.AddSingleton(sp => new GameFunctions.GameFunctions(
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
using HellionChat.Themes.Builtin;
|
using HellionChat.Themes.Builtin;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace HellionChat.Themes;
|
namespace HellionChat.Themes;
|
||||||
|
|
||||||
public sealed class ThemeRegistry
|
public sealed class ThemeRegistry
|
||||||
{
|
{
|
||||||
|
private readonly ILogger<ThemeRegistry>? _logger;
|
||||||
|
|
||||||
public const string DefaultSlug = HellionArctic.Slug;
|
public const string DefaultSlug = HellionArctic.Slug;
|
||||||
|
|
||||||
// 1Hz throttle for the v1.4.8 B2 auto-refresh-on-active path. The
|
// 1Hz throttle for the v1.4.8 B2 auto-refresh-on-active path. The
|
||||||
@@ -29,8 +32,9 @@ public sealed class ThemeRegistry
|
|||||||
private long _lastActiveStampCheckMs = -ActiveStampPollIntervalMs;
|
private long _lastActiveStampCheckMs = -ActiveStampPollIntervalMs;
|
||||||
private DateTime _lastActiveStamp = DateTime.MinValue;
|
private DateTime _lastActiveStamp = DateTime.MinValue;
|
||||||
|
|
||||||
public ThemeRegistry(string? customThemesDir = null)
|
public ThemeRegistry(string? customThemesDir = null, ILogger<ThemeRegistry>? logger = null)
|
||||||
{
|
{
|
||||||
|
_logger = logger;
|
||||||
// Insertion order drives the Theme-Picker grid layout (3 columns).
|
// Insertion order drives the Theme-Picker grid layout (3 columns).
|
||||||
// Row 1: blue family. Row 2: purple to magenta family.
|
// Row 1: blue family. Row 2: purple to magenta family.
|
||||||
// Row 3: green / warm / classic. Row 4: Synthwave Sunset as a
|
// Row 3: green / warm / classic. Row 4: Synthwave Sunset as a
|
||||||
@@ -206,7 +210,7 @@ public sealed class ThemeRegistry
|
|||||||
catch (Exception ex) when (IsRecoverableFileLock(ex))
|
catch (Exception ex) when (IsRecoverableFileLock(ex))
|
||||||
{
|
{
|
||||||
// Editor mid-save: keep last known good, retry on next refresh.
|
// Editor mid-save: keep last known good, retry on next refresh.
|
||||||
Plugin.LogProxy.Debug(
|
_logger?.LogDebug(
|
||||||
$"Custom theme {Path.GetFileName(path)} is locked, keeping last known good"
|
$"Custom theme {Path.GetFileName(path)} is locked, keeping last known good"
|
||||||
);
|
);
|
||||||
if (cached.Theme is not null)
|
if (cached.Theme is not null)
|
||||||
|
|||||||
@@ -124,8 +124,10 @@ public sealed class ChatLogWindow : Window
|
|||||||
DisableWindowSounds = true;
|
DisableWindowSounds = true;
|
||||||
// AllowBackgroundBlur is set centrally in Plugin.Setup after AddWindow.
|
// AllowBackgroundBlur is set centrally in Plugin.Setup after AddWindow.
|
||||||
|
|
||||||
PayloadHandler = new PayloadHandler(this);
|
PayloadHandler = new PayloadHandler(this, _loggerFactory.CreateLogger<PayloadHandler>());
|
||||||
HandlerLender = new Lender<PayloadHandler>(() => new PayloadHandler(this));
|
HandlerLender = new Lender<PayloadHandler>(() =>
|
||||||
|
new PayloadHandler(this, _loggerFactory.CreateLogger<PayloadHandler>())
|
||||||
|
);
|
||||||
|
|
||||||
SetUpTextCommandChannels();
|
SetUpTextCommandChannels();
|
||||||
SetUpAllCommands();
|
SetUpAllCommands();
|
||||||
|
|||||||
Reference in New Issue
Block a user