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 /// The SMAPI version which deprecated it. /// How deprecated the code is. /// A list of stack trace substrings which should suppress deprecation warnings if they appear in the stack trace. - public void Warn(IModMetadata? source, string nounPhrase, string version, DeprecationLevel severity, string[]? unlessStackIncludes = null) + /// Whether to log a stack trace showing where the deprecated code is in the mod. + 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 ?? ""}::{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 { /// A deprecation warning for a mod. @@ -26,6 +24,9 @@ namespace StardewModdingAPI.Framework.Deprecations /// The stack trace when the deprecation warning was raised. public ImmutableStackTrace StackTrace { get; } + /// Whether to log a stack trace showing where the deprecated code is in the mod. + public bool LogStackTrace { get; } + /********* ** Public methods @@ -36,13 +37,15 @@ namespace StardewModdingAPI.Framework.Deprecations /// The SMAPI version which deprecated it. /// The deprecation level for the affected code. /// The stack trace when the deprecation warning was raised. - public DeprecationWarning(IModMetadata? mod, string nounPhrase, string version, DeprecationLevel level, ImmutableStackTrace stackTrace) + /// Whether to log a stack trace showing where the deprecated code is in the mod. + 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(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(metadata, loader));