summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md3
-rw-r--r--src/SMAPI/Framework/Monitor.cs13
-rw-r--r--src/SMAPI/IMonitor.cs5
3 files changed, 20 insertions, 1 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 67d043a1..73fa8ed1 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -12,7 +12,8 @@
* For modders:
* Added support for flipped and rotated map tiles (in collaboration with Platonymous).
* Added support for `.tmx` maps using zlib compression (thanks to Platonymous!).
- * Mods are no longer prevented from suppressing key presses in the chatbox. Use this power wisely.
+ * Added `this.Monitor.LogOnce` method.
+ * Mods are no longer prevented from suppressing key presses in the chatbox.
* For the web UI:
* Added option to upload files using a file picker.
diff --git a/src/SMAPI/Framework/Monitor.cs b/src/SMAPI/Framework/Monitor.cs
index 06cf1b46..f630c7fe 100644
--- a/src/SMAPI/Framework/Monitor.cs
+++ b/src/SMAPI/Framework/Monitor.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using System.Linq;
using StardewModdingAPI.Framework.Logging;
using StardewModdingAPI.Internal.ConsoleWriting;
@@ -26,6 +27,9 @@ namespace StardewModdingAPI.Framework
/// <summary>The maximum length of the <see cref="LogLevel"/> values.</summary>
private static readonly int MaxLevelLength = (from level in Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>() select level.ToString().Length).Max();
+ /// <summary>A cache of messages that should only be logged once.</summary>
+ private readonly HashSet<string> LogOnceCache = new HashSet<string>();
+
/*********
** Accessors
@@ -74,6 +78,15 @@ namespace StardewModdingAPI.Framework
this.LogImpl(this.Source, message, (ConsoleLogLevel)level);
}
+ /// <summary>Log a message for the player or developer, but only if it hasn't already been logged since the last game launch.</summary>
+ /// <param name="message">The message to log.</param>
+ /// <param name="level">The log severity level.</param>
+ public void LogOnce(string message, LogLevel level = LogLevel.Trace)
+ {
+ if (this.LogOnceCache.Add($"{message}|{level}"))
+ this.LogImpl(this.Source, message, (ConsoleLogLevel)level);
+ }
+
/// <summary>Log a message that only appears when <see cref="IMonitor.IsVerbose"/> is enabled.</summary>
/// <param name="message">The message to log.</param>
public void VerboseLog(string message)
diff --git a/src/SMAPI/IMonitor.cs b/src/SMAPI/IMonitor.cs
index f2d110b8..c400a211 100644
--- a/src/SMAPI/IMonitor.cs
+++ b/src/SMAPI/IMonitor.cs
@@ -18,6 +18,11 @@ namespace StardewModdingAPI
/// <param name="level">The log severity level.</param>
void Log(string message, LogLevel level = LogLevel.Trace);
+ /// <summary>Log a message for the player or developer, but only if it hasn't already been logged since the last game launch.</summary>
+ /// <param name="message">The message to log.</param>
+ /// <param name="level">The log severity level.</param>
+ void LogOnce(string message, LogLevel level = LogLevel.Trace);
+
/// <summary>Log a message that only appears when <see cref="IsVerbose"/> is enabled.</summary>
/// <param name="message">The message to log.</param>
void VerboseLog(string message);