From f9823c2ed091df8c31c6d7338acd69e63f598537 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 14 Nov 2016 19:31:22 -0500 Subject: migrate deprecation manager to new logging (#168) --- .../Framework/DeprecationManager.cs | 23 +++++++++------------- src/StardewModdingAPI/Log.cs | 9 +-------- src/StardewModdingAPI/Program.cs | 3 +-- 3 files changed, 11 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/StardewModdingAPI/Framework/DeprecationManager.cs b/src/StardewModdingAPI/Framework/DeprecationManager.cs index 2d25db09..20549b3f 100644 --- a/src/StardewModdingAPI/Framework/DeprecationManager.cs +++ b/src/StardewModdingAPI/Framework/DeprecationManager.cs @@ -13,24 +13,22 @@ namespace StardewModdingAPI.Framework /// The deprecations which have already been logged (as 'mod name::noun phrase::version'). private readonly HashSet LoggedDeprecations = new HashSet(StringComparer.InvariantCultureIgnoreCase); + /// Encapsulates monitoring and logging for a given module. + private readonly IMonitor Monitor; + /// Tracks the installed mods. private readonly ModRegistry ModRegistry; - /********* - ** Accessors - *********/ - /// Whether -level deprecation messages should be shown in the console. - public bool SendNoticesToConsole { get; set; } - - /********* ** Public methods *********/ /// Construct an instance. + /// Encapsulates monitoring and logging for a given module. /// Tracks the installed mods. - public DeprecationManager(ModRegistry modRegistry) + public DeprecationManager(IMonitor monitor, ModRegistry modRegistry) { + this.Monitor = monitor; this.ModRegistry = modRegistry; } @@ -68,18 +66,15 @@ namespace StardewModdingAPI.Framework switch (severity) { case DeprecationLevel.Notice: - if (this.SendNoticesToConsole) - Log.Debug($"[DEV] {message}"); - else - Log.LogToFile(message); + this.Monitor.Log(message, LogLevel.Trace); break; case DeprecationLevel.Info: - Log.Debug(message); + this.Monitor.Log(message, LogLevel.Info); break; case DeprecationLevel.PendingRemoval: - Log.Warning(message); + this.Monitor.Log(message, LogLevel.Warn); break; default: diff --git a/src/StardewModdingAPI/Log.cs b/src/StardewModdingAPI/Log.cs index b1af111c..9cb32576 100644 --- a/src/StardewModdingAPI/Log.cs +++ b/src/StardewModdingAPI/Log.cs @@ -18,9 +18,6 @@ namespace StardewModdingAPI /// Tracks the installed mods. internal static ModRegistry ModRegistry; - /// A temporary field to avoid infinite loops (since we use a deprecated interface to warn about the deprecated interface). - private static bool WarnedDeprecated; - /********* ** Public methods @@ -181,11 +178,7 @@ namespace StardewModdingAPI /// Raise a deprecation warning. private static void WarnDeprecated() { - if (!Log.WarnedDeprecated) - { - Log.WarnedDeprecated = true; - Program.DeprecationManager.Warn($"the {nameof(Log)} class", "1.1", DeprecationLevel.Notice); - } + Program.DeprecationManager.Warn("an unknown mod", $"the {nameof(Log)} class", "1.1", DeprecationLevel.Notice); } /// Get the name of the mod logging a message from the stack. diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index f4416e70..046d8a36 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -72,7 +72,7 @@ namespace StardewModdingAPI internal static readonly ModRegistry ModRegistry = new ModRegistry(); /// Manages deprecation warnings. - internal static readonly DeprecationManager DeprecationManager = new DeprecationManager(Program.ModRegistry); + internal static readonly DeprecationManager DeprecationManager = new DeprecationManager(Program.Monitor, Program.ModRegistry); /********* @@ -96,7 +96,6 @@ namespace StardewModdingAPI if (Program.DeveloperMode) { - Program.DeprecationManager.SendNoticesToConsole = settings?.DeveloperMode == true; Program.Monitor.ShowTraceInConsole = true; Program.Monitor.Log($"SMAPI is running in developer mode. The console may be much more verbose. You can disable developer mode by deleting the {settingsFileName} file in the game directory.", LogLevel.Alert); } -- cgit