add monitor.LogOnce method

This commit is contained in:
Jesse Plamondon-Willard 2020-03-22 17:40:31 -04:00
parent 8d88ce8a16
commit a50e78efd8
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
3 changed files with 20 additions and 1 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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);