From 691ca31b9535e074007bc85e345655948c6bf143 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 7 Oct 2025 05:45:01 -0600 Subject: [PATCH] (Cleanup) Fix logger obsolete warnings (#40553) * Switched obsolete logger usages to use Sawmill Fix the majority of obsolete logger usages outside the engine code. * Fix injection in ChatManager and revert BuildMech changes * Removed extra manual injection * Reduced extra static injection and reverted changes to CommandButton as it needs engine changes. * Removed two more cases of double injection and an extra using * Reverted changes for Inventory Display * Moved sawmill setup outside constructor in Table to resolve test failure --- .../Administration/UI/Notes/AdminNotesLine.xaml.cs | 7 ++++++- .../Construction/UI/ConstructionMenuPresenter.cs | 8 ++++++-- Content.Client/Guidebook/DocumentParsingManager.cs | 9 ++++----- Content.Client/Guidebook/Richtext/Table.cs | 7 ++++++- Content.Client/Guidebook/Richtext/TextLinkTag.cs | 9 +++++++-- Content.Client/Launcher/LauncherConnecting.cs | 8 ++++++-- .../Systems/Alerts/Widgets/AlertsUI.xaml.cs | 12 +++++++++--- Content.Replay/Menu/ReplayMainMenu.cs | 6 +++++- Content.Server/Chat/Managers/ChatManager.cs | 12 ++++++++---- .../GameTicking/Commands/JoinGameCommand.cs | 7 ++++++- 10 files changed, 63 insertions(+), 22 deletions(-) diff --git a/Content.Client/Administration/UI/Notes/AdminNotesLine.xaml.cs b/Content.Client/Administration/UI/Notes/AdminNotesLine.xaml.cs index 97ddc15000..24e5cfdfab 100644 --- a/Content.Client/Administration/UI/Notes/AdminNotesLine.xaml.cs +++ b/Content.Client/Administration/UI/Notes/AdminNotesLine.xaml.cs @@ -14,6 +14,9 @@ namespace Content.Client.Administration.UI.Notes; [GenerateTypedNameReferences] public sealed partial class AdminNotesLine : BoxContainer { + [Dependency] private readonly ILogManager _logManager = default!; + + private readonly ISawmill _sawmill = default!; private readonly SpriteSystem _sprites; private const string AdminNotesTextureBase = "/Textures/Interface/AdminNotes/"; @@ -33,6 +36,8 @@ public sealed partial class AdminNotesLine : BoxContainer public AdminNotesLine(SpriteSystem sprites, SharedAdminNote note) { RobustXamlLoader.Load(this); + + _sawmill = _logManager.GetSawmill("admin.notes"); _sprites = sprites; Note = note; @@ -61,7 +66,7 @@ public sealed partial class AdminNotesLine : BoxContainer if (iconPath is null) { SeverityRect.Visible = false; - Logger.WarningS("admin.notes", $"Could not find an icon for note ID {Note.Id}"); + _sawmill.Warning($"Could not find an icon for note ID {Note.Id}"); } else { diff --git a/Content.Client/Construction/UI/ConstructionMenuPresenter.cs b/Content.Client/Construction/UI/ConstructionMenuPresenter.cs index d5fee2bdda..d640de7b68 100644 --- a/Content.Client/Construction/UI/ConstructionMenuPresenter.cs +++ b/Content.Client/Construction/UI/ConstructionMenuPresenter.cs @@ -30,8 +30,10 @@ namespace Content.Client.Construction.UI [Dependency] private readonly IUserInterfaceManager _uiManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IClientPreferencesManager _preferencesManager = default!; - private readonly SpriteSystem _spriteSystem; + [Dependency] private readonly ILogManager _logManager = default!; + private readonly ISawmill _sawmill = default!; + private readonly SpriteSystem _spriteSystem; private readonly IConstructionMenuView _constructionView; private readonly EntityWhitelistSystem _whitelistSystem; @@ -87,6 +89,8 @@ namespace Content.Client.Construction.UI { // This is a lot easier than a factory IoCManager.InjectDependencies(this); + _sawmill = _logManager.GetSawmill("construction.menu"); + _constructionView = new ConstructionMenu(); _whitelistSystem = _entManager.System(); _spriteSystem = _entManager.System(); @@ -284,7 +288,7 @@ namespace Content.Client.Construction.UI if (!_constructionSystem!.TryGetRecipePrototype(recipe.ID, out var targetProtoId)) { - Logger.Error("Cannot find the target prototype in the recipe cache with the id \"{0}\" of {1}.", + _sawmill.Error("Cannot find the target prototype in the recipe cache with the id \"{0}\" of {1}.", recipe.ID, nameof(ConstructionPrototype)); continue; diff --git a/Content.Client/Guidebook/DocumentParsingManager.cs b/Content.Client/Guidebook/DocumentParsingManager.cs index 8bc1a834fc..4c9f5fabe0 100644 --- a/Content.Client/Guidebook/DocumentParsingManager.cs +++ b/Content.Client/Guidebook/DocumentParsingManager.cs @@ -7,7 +7,6 @@ using Robust.Client.UserInterface; using Robust.Shared.ContentPack; using Robust.Shared.Prototypes; using Robust.Shared.Reflection; -using Robust.Shared.Sandboxing; using Robust.Shared.Utility; using static Pidgin.Parser; @@ -21,7 +20,7 @@ public sealed partial class DocumentParsingManager [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly IReflectionManager _reflectionManager = default!; [Dependency] private readonly IResourceManager _resourceManager = default!; - [Dependency] private readonly ISandboxHelper _sandboxHelper = default!; + [Dependency] private readonly IDynamicTypeFactory _dynamicTypeFactory = default!; private readonly Dictionary> _tagControlParsers = new(); private Parser _controlParser = default!; @@ -43,7 +42,7 @@ public sealed partial class DocumentParsingManager foreach (var typ in _reflectionManager.GetAllChildren()) { - _tagControlParsers.Add(typ.Name, CreateTagControlParser(typ.Name, typ, _sandboxHelper)); + _tagControlParsers.Add(typ.Name, CreateTagControlParser(typ.Name, typ, _dynamicTypeFactory)); } ControlParser = whitespaceAndCommentParser.Then(_controlParser.Many()); @@ -87,14 +86,14 @@ public sealed partial class DocumentParsingManager return true; } - private Parser CreateTagControlParser(string tagId, Type tagType, ISandboxHelper sandbox) + private Parser CreateTagControlParser(string tagId, Type tagType, IDynamicTypeFactory typeFactory) { return Map( (args, controls) => { try { - var tag = (IDocumentTag) sandbox.CreateInstance(tagType); + var tag = (IDocumentTag) typeFactory.CreateInstance(tagType); if (!tag.TryParseTag(args, out var control)) { _sawmill.Error($"Failed to parse {tagId} args"); diff --git a/Content.Client/Guidebook/Richtext/Table.cs b/Content.Client/Guidebook/Richtext/Table.cs index b6923c3698..82b884aa96 100644 --- a/Content.Client/Guidebook/Richtext/Table.cs +++ b/Content.Client/Guidebook/Richtext/Table.cs @@ -8,6 +8,11 @@ namespace Content.Client.Guidebook.Richtext; [UsedImplicitly] public sealed class Table : TableContainer, IDocumentTag { + [Dependency] private readonly ILogManager _logManager = default!; + + private ISawmill Sawmill => _sawmill ??= _logManager.GetSawmill("table"); + private ISawmill? _sawmill; + public bool TryParseTag(Dictionary args, [NotNullWhen(true)] out Control? control) { HorizontalExpand = true; @@ -15,7 +20,7 @@ public sealed class Table : TableContainer, IDocumentTag if (!args.TryGetValue("Columns", out var columns) || !int.TryParse(columns, out var columnsCount)) { - Logger.Error("Guidebook tag \"Table\" does not specify required property \"Columns.\""); + Sawmill.Error("Guidebook tag \"Table\" does not specify required property \"Columns.\""); control = null; return false; } diff --git a/Content.Client/Guidebook/Richtext/TextLinkTag.cs b/Content.Client/Guidebook/Richtext/TextLinkTag.cs index a551b18473..5c0098d5b5 100644 --- a/Content.Client/Guidebook/Richtext/TextLinkTag.cs +++ b/Content.Client/Guidebook/Richtext/TextLinkTag.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using JetBrains.Annotations; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -12,6 +12,11 @@ namespace Content.Client.Guidebook.RichText; [UsedImplicitly] public sealed class TextLinkTag : IMarkupTagHandler { + [Dependency] private readonly ILogManager _logManager = default!; + + private ISawmill Sawmill => _sawmill ??= _logManager.GetSawmill(Name); + private ISawmill? _sawmill; + public static Color LinkColor => Color.CornflowerBlue; public string Name => "textlink"; @@ -53,7 +58,7 @@ public sealed class TextLinkTag : IMarkupTagHandler if (control.TryGetParentHandler(out var handler)) handler.HandleClick(link); else - Logger.Warning("Warning! No valid ILinkClickHandler found."); + Sawmill.Warning("Warning! No valid ILinkClickHandler found."); } } diff --git a/Content.Client/Launcher/LauncherConnecting.cs b/Content.Client/Launcher/LauncherConnecting.cs index 33d31cc52d..3496c92aba 100644 --- a/Content.Client/Launcher/LauncherConnecting.cs +++ b/Content.Client/Launcher/LauncherConnecting.cs @@ -20,7 +20,9 @@ namespace Content.Client.Launcher [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IClipboardManager _clipboard = default!; + [Dependency] private readonly ILogManager _logManager = default!; + private ISawmill _sawmill = default!; private LauncherConnectingGui? _control; private Page _currentPage; @@ -59,6 +61,8 @@ namespace Content.Client.Launcher protected override void Startup() { + _sawmill = _logManager.GetSawmill("launcher-ui"); + _control = new LauncherConnectingGui(this, _random, _prototypeManager, _cfg, _clipboard); _userInterfaceManager.StateRoot.AddChild(_control); @@ -115,12 +119,12 @@ namespace Content.Client.Launcher } else { - Logger.InfoS("launcher-ui", $"Redial not possible, no Ss14Address"); + _sawmill.Info($"Redial not possible, no Ss14Address"); } } catch (Exception ex) { - Logger.ErrorS("launcher-ui", $"Redial exception: {ex}"); + _sawmill.Error($"Redial exception: {ex}"); } return false; } diff --git a/Content.Client/UserInterface/Systems/Alerts/Widgets/AlertsUI.xaml.cs b/Content.Client/UserInterface/Systems/Alerts/Widgets/AlertsUI.xaml.cs index d6a79a81c4..9d62f0c9be 100644 --- a/Content.Client/UserInterface/Systems/Alerts/Widgets/AlertsUI.xaml.cs +++ b/Content.Client/UserInterface/Systems/Alerts/Widgets/AlertsUI.xaml.cs @@ -14,12 +14,18 @@ namespace Content.Client.UserInterface.Systems.Alerts.Widgets; [GenerateTypedNameReferences] public sealed partial class AlertsUI : UIWidget { + [Dependency] private readonly ILogManager _logManager = default!; + + private readonly ISawmill _sawmill = default!; + // also known as Control.Children? private readonly Dictionary _alertControls = new(); public AlertsUI() { RobustXamlLoader.Load(this); + + _sawmill = _logManager.GetSawmill("alertsui"); } public void SyncControls(AlertsSystem alertsSystem, @@ -78,15 +84,15 @@ public sealed partial class AlertsUI : UIWidget { if (!alertKey.AlertType.HasValue) { - Logger.WarningS("alert", "found alertkey without alerttype," + - " alert keys should never be stored without an alerttype set: {0}", alertKey); + _sawmill.Warning("found alertkey without alerttype," + + " alert keys should never be stored without an alerttype set: {0}", alertKey); continue; } var alertType = alertKey.AlertType.Value; if (!alertsSystem.TryGet(alertType, out var newAlert)) { - Logger.ErrorS("alert", "Unrecognized alertType {0}", alertType); + _sawmill.Error("Unrecognized alertType {0}", alertType); continue; } diff --git a/Content.Replay/Menu/ReplayMainMenu.cs b/Content.Replay/Menu/ReplayMainMenu.cs index 85c39c59da..5adb769942 100644 --- a/Content.Replay/Menu/ReplayMainMenu.cs +++ b/Content.Replay/Menu/ReplayMainMenu.cs @@ -33,7 +33,9 @@ public sealed class ReplayMainScreen : State [Dependency] private readonly IClientRobustSerializer _serializer = default!; [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; [Dependency] private readonly ContentReplayPlaybackManager _replayMan = default!; + [Dependency] private readonly ILogManager _logManager = default!; + private ISawmill _sawmill = default!; private ReplayMainMenuControl _mainMenuControl = default!; private SelectReplayWindow? _selectWindow; private ResPath _directory; @@ -42,6 +44,8 @@ public sealed class ReplayMainScreen : State protected override void Startup() { + _sawmill = _logManager.GetSawmill("replay.screen"); + _mainMenuControl = new(_resourceCache); _userInterfaceManager.StateRoot.AddChild(_mainMenuControl); @@ -263,7 +267,7 @@ public sealed class ReplayMainScreen : State } catch (Exception ex) { - Logger.Error($"Failed to load replay info. Exception: {ex}"); + _sawmill.Error($"Failed to load replay info. Exception: {ex}"); SelectReplay(null); return; } diff --git a/Content.Server/Chat/Managers/ChatManager.cs b/Content.Server/Chat/Managers/ChatManager.cs index c62a10ada3..a37c05336f 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -1,6 +1,3 @@ -using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Runtime.InteropServices; using Content.Server.Administration.Logs; using Content.Server.Administration.Managers; using Content.Server.Administration.Systems; @@ -18,6 +15,9 @@ using Robust.Shared.Network; using Robust.Shared.Player; using Robust.Shared.Replays; using Robust.Shared.Utility; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Runtime.InteropServices; namespace Content.Server.Chat.Managers; @@ -45,6 +45,7 @@ internal sealed partial class ChatManager : IChatManager [Dependency] private readonly PlayerRateLimitManager _rateLimitManager = default!; [Dependency] private readonly ISharedPlayerManager _player = default!; [Dependency] private readonly DiscordChatLink _discordLink = default!; + [Dependency] private readonly ILogManager _logManager = default!; /// /// The maximum length a player-sent message can be sent @@ -54,6 +55,7 @@ internal sealed partial class ChatManager : IChatManager private bool _oocEnabled = true; private bool _adminOocEnabled = true; + private ISawmill _sawmill = default!; private readonly Dictionary _players = new(); public void Initialize() @@ -64,6 +66,8 @@ internal sealed partial class ChatManager : IChatManager _configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true); _configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true); + _sawmill = _logManager.GetSawmill("SERVER"); + RegisterRateLimits(); } @@ -111,7 +115,7 @@ internal sealed partial class ChatManager : IChatManager { var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", FormattedMessage.EscapeText(message))); ChatMessageToAll(ChatChannel.Server, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride); - Logger.InfoS("SERVER", message); + _sawmill.Info(message); _adminLogger.Add(LogType.Chat, LogImpact.Low, $"Server announcement: {message}"); } diff --git a/Content.Server/GameTicking/Commands/JoinGameCommand.cs b/Content.Server/GameTicking/Commands/JoinGameCommand.cs index a32a2f9495..bfb3d91464 100644 --- a/Content.Server/GameTicking/Commands/JoinGameCommand.cs +++ b/Content.Server/GameTicking/Commands/JoinGameCommand.cs @@ -13,11 +13,14 @@ namespace Content.Server.GameTicking.Commands [AnyCommand] sealed class JoinGameCommand : IConsoleCommand { + [Dependency] private readonly ILogManager _logManager = default!; [Dependency] private readonly IEntityManager _entManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IAdminManager _adminManager = default!; [Dependency] private readonly IConfigurationManager _cfg = default!; + private readonly ISawmill _sawmill = default!; + public string Command => "joingame"; public string Description => ""; public string Help => ""; @@ -25,6 +28,8 @@ namespace Content.Server.GameTicking.Commands public JoinGameCommand() { IoCManager.InjectDependencies(this); + + _sawmill = _logManager.GetSawmill("security"); } public void Execute(IConsoleShell shell, string argStr, string[] args) { @@ -46,7 +51,7 @@ namespace Content.Server.GameTicking.Commands if (ticker.PlayerGameStatuses.TryGetValue(player.UserId, out var status) && status == PlayerGameStatus.JoinedGame) { - Logger.InfoS("security", $"{player.Name} ({player.UserId}) attempted to latejoin while in-game."); + _sawmill.Info($"{player.Name} ({player.UserId}) attempted to latejoin while in-game."); shell.WriteError($"{player.Name} is not in the lobby. This incident will be reported."); return; } -- 2.51.2