From 971bfd32d2f44d2fa1795807ce1ba1b700ff4f86 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 26 Apr 2017 16:22:41 -0400 Subject: detect exceptions logged directly to the console and log them as errors --- release-notes.md | 3 ++- src/StardewModdingAPI/Program.cs | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/release-notes.md b/release-notes.md index dc800704..311128d0 100644 --- a/release-notes.md +++ b/release-notes.md @@ -15,9 +15,10 @@ See [log](https://github.com/Pathoschild/SMAPI/compare/1.10...1.11). For players: * Optimised console logging. +* Errors when loading a save are now shown in the SMAPI console. For mod developers: -* `Console.Out` messages are now written to the log file. +* `Console.Out` messages are now written to the log file. ## 1.10 See [log](https://github.com/Pathoschild/SMAPI/compare/1.9...1.10). 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 } } + /// Redirect messages logged directly to the console to the given monitor. + /// The monitor with which to log messages. + /// The message to log. + private void HandleConsoleMessage(IMonitor monitor, string message) + { + LogLevel level = message.Contains("Exception") ? LogLevel.Error : LogLevel.Trace; // intercept potential exceptions + monitor.Log(message, level); + } + /// Show a 'press any key to exit' message, and exit when they press a key. private void PressAnyKeyToExit() { -- cgit