omit stack trace for deprecated code not called directly by the mod
This commit is contained in:
parent
ed337ab964
commit
7bb7a7522f
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue