summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-04-26 16:22:41 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-04-26 16:22:41 -0400
commit971bfd32d2f44d2fa1795807ce1ba1b700ff4f86 (patch)
tree23480fa01fe5fb0b00122973c5e3e5a6057156c3 /src/StardewModdingAPI
parentafc8ae69fead4099ac86dcea6aa874f5b1540e29 (diff)
downloadSMAPI-971bfd32d2f44d2fa1795807ce1ba1b700ff4f86.tar.gz
SMAPI-971bfd32d2f44d2fa1795807ce1ba1b700ff4f86.tar.bz2
SMAPI-971bfd32d2f44d2fa1795807ce1ba1b700ff4f86.zip
detect exceptions logged directly to the console and log them as errors
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Program.cs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index 18a5c999..6e57fd65 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -248,7 +248,7 @@ namespace StardewModdingAPI
{
Monitor monitor = this.GetSecondaryMonitor("Console.Out");
if (monitor.WriteToConsole)
- this.ConsoleManager.OnMessageIntercepted += line => monitor.Log(line, LogLevel.Trace);
+ this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(monitor, message);
}
// add warning headers
@@ -603,6 +603,15 @@ namespace StardewModdingAPI
}
}
+ /// <summary>Redirect messages logged directly to the console to the given monitor.</summary>
+ /// <param name="monitor">The monitor with which to log messages.</param>
+ /// <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
+ monitor.Log(message, level);
+ }
+
/// <summary>Show a 'press any key to exit' message, and exit when they press a key.</summary>
private void PressAnyKeyToExit()
{