hide the game's test messages from the console & log (#364)

This commit is contained in:
Jesse Plamondon-Willard 2017-10-27 01:42:54 -04:00
parent f63484e5e7
commit 7f16ebdb19
2 changed files with 17 additions and 1 deletions

View File

@ -2,6 +2,7 @@
## 2.1 (upcoming)
* For players:
* Fixed compatibility check crashing for players with Stardew Valley 1.08.
* Fixed the game's test messages being shown in the console and log.
* For modders:
* Added support for public code in reflection API, to simplify mod integrations.

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Text.RegularExpressions;
using System.Threading;
#if SMAPI_FOR_WINDOWS
using System.Management;
@ -77,6 +78,13 @@ namespace StardewModdingAPI
/// <summary>Whether the program has been disposed.</summary>
private bool IsDisposed;
/// <summary>Regex patterns which match console messages to suppress from the console and log.</summary>
private readonly Regex[] SuppressConsolePatterns =
{
new Regex(@"^TextBox\.Selected is now '(?:True|False)'\.$", RegexOptions.Compiled | RegexOptions.CultureInvariant),
new Regex(@"^(?:FRUIT )?TREE: IsClient:(?:True|False) randomOutput: \d+$", RegexOptions.Compiled | RegexOptions.CultureInvariant)
};
/*********
** Public methods
@ -910,7 +918,14 @@ namespace StardewModdingAPI
/// <param name="message">The message to log.</param>
private void HandleConsoleMessage(IMonitor monitor, string message)
{
LogLevel level = message.Contains("Exception") ? LogLevel.Error : LogLevel.Trace; // intercept potential exceptions
// detect exception
LogLevel level = message.Contains("Exception") ? LogLevel.Error : LogLevel.Trace;
// ignore suppressed message
if (level != LogLevel.Error && this.SuppressConsolePatterns.Any(p => p.IsMatch(message)))
return;
// forward to monitor
monitor.Log(message, level);
}