summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Framework/DeprecationManager.cs23
-rw-r--r--src/StardewModdingAPI/Log.cs9
-rw-r--r--src/StardewModdingAPI/Program.cs3
3 files changed, 11 insertions, 24 deletions
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
/// <summary>The deprecations which have already been logged (as 'mod name::noun phrase::version').</summary>
private readonly HashSet<string> LoggedDeprecations = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
+ /// <summary>Encapsulates monitoring and logging for a given module.</summary>
+ private readonly IMonitor Monitor;
+
/// <summary>Tracks the installed mods.</summary>
private readonly ModRegistry ModRegistry;
/*********
- ** Accessors
- *********/
- /// <summary>Whether <see cref="DeprecationLevel.Notice"/>-level deprecation messages should be shown in the console.</summary>
- public bool SendNoticesToConsole { get; set; }
-
-
- /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <param name="monitor">Encapsulates monitoring and logging for a given module.</param>
/// <param name="modRegistry">Tracks the installed mods.</param>
- 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
/// <summary>Tracks the installed mods.</summary>
internal static ModRegistry ModRegistry;
- /// <summary>A temporary field to avoid infinite loops (since we use a deprecated interface to warn about the deprecated interface).</summary>
- private static bool WarnedDeprecated;
-
/*********
** Public methods
@@ -181,11 +178,7 @@ namespace StardewModdingAPI
/// <summary>Raise a deprecation warning.</summary>
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);
}
/// <summary>Get the name of the mod logging a message from the stack.</summary>
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();
/// <summary>Manages deprecation warnings.</summary>
- 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);
}