From b73234b56d816ba68c0f92a9d356ea85941dca94 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 27 Sep 2018 01:23:17 -0400 Subject: log base update loop errors as 'game' instead of SMAPI --- src/SMAPI/Framework/SCore.cs | 13 +++++++------ src/SMAPI/Framework/SGame.cs | 13 +++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 24a15fc6..5f30c9ef 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -52,6 +52,9 @@ namespace StardewModdingAPI.Framework /// The core logger and monitor for SMAPI. private readonly Monitor Monitor; + /// The core logger and monitor on behalf of the game. + private readonly Monitor MonitorForGame; + /// Tracks whether the game should exit immediately and any pending initialisation should be cancelled. private readonly CancellationTokenSource CancellationTokenSource = new CancellationTokenSource(); @@ -128,6 +131,7 @@ namespace StardewModdingAPI.Framework ShowTraceInConsole = this.Settings.DeveloperMode, ShowFullStampInConsole = this.Settings.DeveloperMode }; + this.MonitorForGame = this.GetSecondaryMonitor("game"); this.EventManager = new EventManager(this.Monitor, this.ModRegistry); // init logging @@ -200,7 +204,7 @@ namespace StardewModdingAPI.Framework // override game SGame.ConstructorHack = new SGameConstructorHack(this.Monitor, this.Reflection, this.Toolkit.JsonHelper); - this.GameInstance = new SGame(this.Monitor, this.Reflection, this.EventManager, this.InitialiseAfterGameStart, this.Dispose); + this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.InitialiseAfterGameStart, this.Dispose); StardewValley.Program.gamePtr = this.GameInstance; // add exit handler @@ -338,11 +342,8 @@ namespace StardewModdingAPI.Framework this.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry); // redirect direct console output - { - Monitor monitor = this.GetSecondaryMonitor("game"); - if (monitor.WriteToConsole) - this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(monitor, message); - } + if (this.MonitorForGame.WriteToConsole) + this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message); // add headers if (this.Settings.DeveloperMode) diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 166f958c..1bd583bf 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -39,9 +39,12 @@ namespace StardewModdingAPI.Framework /**** ** SMAPI state ****/ - /// Encapsulates monitoring and logging. + /// Encapsulates monitoring and logging for SMAPI. private readonly IMonitor Monitor; + /// Encapsulates monitoring and logging on the game's behalf. + private readonly IMonitor MonitorForGame; + /// Manages SMAPI events for mods. private readonly EventManager Events; @@ -122,12 +125,13 @@ namespace StardewModdingAPI.Framework ** Protected methods *********/ /// Construct an instance. - /// Encapsulates monitoring and logging. + /// Encapsulates monitoring and logging for SMAPI. + /// Encapsulates monitoring and logging on the game's behalf. /// Simplifies access to private game code. /// Manages SMAPI events for mods. /// A callback to invoke after the game finishes initialising. /// A callback to invoke when the game exits. - internal SGame(IMonitor monitor, Reflector reflection, EventManager eventManager, Action onGameInitialised, Action onGameExiting) + internal SGame(IMonitor monitor, IMonitor monitorForGame, Reflector reflection, EventManager eventManager, Action onGameInitialised, Action onGameExiting) { SGame.ConstructorHack = null; @@ -140,6 +144,7 @@ namespace StardewModdingAPI.Framework // init SMAPI this.Monitor = monitor; + this.MonitorForGame = monitorForGame; this.Events = eventManager; this.Reflection = reflection; this.OnGameInitialised = onGameInitialised; @@ -697,7 +702,7 @@ namespace StardewModdingAPI.Framework } catch (Exception ex) { - this.Monitor.Log($"An error occured in the base update loop: {ex.GetLogSummary()}", LogLevel.Error); + this.MonitorForGame.Log($"An error occured in the base update loop: {ex.GetLogSummary()}", LogLevel.Error); } this.Events.GameLoop_Updated.Raise(new GameLoopUpdatedEventArgs(this.TicksElapsed)); -- cgit