summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-30 12:57:28 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-30 12:57:28 -0400
commit7bb7a7522fcdfef27f8f22ba77f24c7609f49912 (patch)
tree4a0a9325b9c177d096a92172699cfbd022653b39 /src/SMAPI/Framework
parented337ab9644527465205547bd7e319194df553ab (diff)
downloadSMAPI-7bb7a7522fcdfef27f8f22ba77f24c7609f49912.tar.gz
SMAPI-7bb7a7522fcdfef27f8f22ba77f24c7609f49912.tar.bz2
SMAPI-7bb7a7522fcdfef27f8f22ba77f24c7609f49912.zip
omit stack trace for deprecated code not called directly by the mod
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/Deprecations/DeprecationManager.cs14
-rw-r--r--src/SMAPI/Framework/Deprecations/DeprecationWarning.cs9
-rw-r--r--src/SMAPI/Framework/SCore.cs6
3 files changed, 20 insertions, 9 deletions
diff --git a/src/SMAPI/Framework/Deprecations/DeprecationManager.cs b/src/SMAPI/Framework/Deprecations/DeprecationManager.cs
index 5ca07702..288abde2 100644
--- a/src/SMAPI/Framework/Deprecations/DeprecationManager.cs
+++ b/src/SMAPI/Framework/Deprecations/DeprecationManager.cs
@@ -57,7 +57,8 @@ namespace StardewModdingAPI.Framework.Deprecations
/// <param name="version">The SMAPI version which deprecated it.</param>
/// <param name="severity">How deprecated the code is.</param>
/// <param name="unlessStackIncludes">A list of stack trace substrings which should suppress deprecation warnings if they appear in the stack trace.</param>
- public void Warn(IModMetadata? source, string nounPhrase, string version, DeprecationLevel severity, string[]? unlessStackIncludes = null)
+ /// <param name="logStackTrace">Whether to log a stack trace showing where the deprecated code is in the mod.</param>
+ public void Warn(IModMetadata? source, string nounPhrase, string version, DeprecationLevel severity, string[]? unlessStackIncludes = null, bool logStackTrace = true)
{
// skip if already warned
string cacheKey = $"{source?.DisplayName ?? "<unknown>"}::{nounPhrase}::{version}";
@@ -69,7 +70,7 @@ namespace StardewModdingAPI.Framework.Deprecations
if (!this.ShouldSuppress(stack, unlessStackIncludes))
{
this.LoggedDeprecations.Add(cacheKey);
- this.QueuedWarnings.Add(new DeprecationWarning(source, nounPhrase, version, severity, stack));
+ this.QueuedWarnings.Add(new DeprecationWarning(source, nounPhrase, version, severity, stack, logStackTrace));
}
}
@@ -108,11 +109,16 @@ namespace StardewModdingAPI.Framework.Deprecations
// log message
if (level == LogLevel.Trace)
- this.Monitor.Log($"{message}\n{this.GetSimplifiedStackTrace(warning.StackTrace, warning.Mod)}", level);
+ {
+ if (warning.LogStackTrace)
+ message += $"\n{this.GetSimplifiedStackTrace(warning.StackTrace, warning.Mod)}";
+ this.Monitor.Log(message, level);
+ }
else
{
this.Monitor.Log(message, level);
- this.Monitor.Log(this.GetSimplifiedStackTrace(warning.StackTrace, warning.Mod), LogLevel.Debug);
+ if (warning.LogStackTrace)
+ this.Monitor.Log(this.GetSimplifiedStackTrace(warning.StackTrace, warning.Mod), LogLevel.Debug);
}
}
diff --git a/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs b/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs
index e00881b1..5936517b 100644
--- a/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs
+++ b/src/SMAPI/Framework/Deprecations/DeprecationWarning.cs
@@ -1,5 +1,3 @@
-using System.Diagnostics;
-
namespace StardewModdingAPI.Framework.Deprecations
{
/// <summary>A deprecation warning for a mod.</summary>
@@ -26,6 +24,9 @@ namespace StardewModdingAPI.Framework.Deprecations
/// <summary>The stack trace when the deprecation warning was raised.</summary>
public ImmutableStackTrace StackTrace { get; }
+ /// <summary>Whether to log a stack trace showing where the deprecated code is in the mod.</summary>
+ public bool LogStackTrace { get; }
+
/*********
** Public methods
@@ -36,13 +37,15 @@ namespace StardewModdingAPI.Framework.Deprecations
/// <param name="version">The SMAPI version which deprecated it.</param>
/// <param name="level">The deprecation level for the affected code.</param>
/// <param name="stackTrace">The stack trace when the deprecation warning was raised.</param>
- public DeprecationWarning(IModMetadata? mod, string nounPhrase, string version, DeprecationLevel level, ImmutableStackTrace stackTrace)
+ /// <param name="logStackTrace">Whether to log a stack trace showing where the deprecated code is in the mod.</param>
+ public DeprecationWarning(IModMetadata? mod, string nounPhrase, string version, DeprecationLevel level, ImmutableStackTrace stackTrace, bool logStackTrace)
{
this.Mod = mod;
this.NounPhrase = nounPhrase;
this.Version = version;
this.Level = level;
this.StackTrace = stackTrace;
+ this.LogStackTrace = logStackTrace;
}
}
}
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index c208788a..e64318a5 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -1604,7 +1604,8 @@ namespace StardewModdingAPI.Framework
source: metadata,
nounPhrase: $"{nameof(IAssetEditor)}",
version: "3.14.0",
- severity: DeprecationLevel.Notice
+ severity: DeprecationLevel.Notice,
+ logStackTrace: false
);
this.ContentCore.Editors.Add(new ModLinked<IAssetEditor>(metadata, editor));
@@ -1616,7 +1617,8 @@ namespace StardewModdingAPI.Framework
source: metadata,
nounPhrase: $"{nameof(IAssetLoader)}",
version: "3.14.0",
- severity: DeprecationLevel.Notice
+ severity: DeprecationLevel.Notice,
+ logStackTrace: false
);
this.ContentCore.Loaders.Add(new ModLinked<IAssetLoader>(metadata, loader));