diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-02 21:24:32 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-07-02 21:24:32 -0400 |
commit | 6a628a4d8a21b98a55ff29065980fc818d4f39dc (patch) | |
tree | 6a68e9e7065d21102600ac7921807b5f7f54dd2e | |
parent | 0e6d30f65b562704675a20b1c4ce399787a68511 (diff) | |
download | SMAPI-6a628a4d8a21b98a55ff29065980fc818d4f39dc.tar.gz SMAPI-6a628a4d8a21b98a55ff29065980fc818d4f39dc.tar.bz2 SMAPI-6a628a4d8a21b98a55ff29065980fc818d4f39dc.zip |
simplify log timestamps in console (except in developer mode)
-rw-r--r-- | release-notes.md | 2 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Monitor.cs | 13 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 8 |
3 files changed, 17 insertions, 6 deletions
diff --git a/release-notes.md b/release-notes.md index b5a8a529..c5d0ccef 100644 --- a/release-notes.md +++ b/release-notes.md @@ -13,7 +13,7 @@ For mod developers: See [log](https://github.com/Pathoschild/SMAPI/compare/1.14...1.15). For players: -* Many changes to the SMAPI console to make it simpler for players. +* Several changes to the SMAPI console to make it simpler for players. * Revamped TrainerMod's item commands: * `player_add` is a new command which lets you add any game item to your inventory (including tools, weapons, equipment, craftables, wallpaper, etc). This replaces the former `player_additem`, `player_addring`, and `player_addweapon`. * `list_items` now shows all items in the game. You can search by item type like `list_items weapon`, or search by item name like `list_items galaxy sword`. diff --git a/src/StardewModdingAPI/Framework/Monitor.cs b/src/StardewModdingAPI/Framework/Monitor.cs index 925efc33..b64b3b0b 100644 --- a/src/StardewModdingAPI/Framework/Monitor.cs +++ b/src/StardewModdingAPI/Framework/Monitor.cs @@ -45,6 +45,9 @@ namespace StardewModdingAPI.Framework /// <summary>Whether SMAPI is aborting. Mods don't need to worry about this unless they have background tasks.</summary> public bool IsExiting => this.ExitTokenSource.IsCancellationRequested; + /// <summary>Whether to show the full log stamps (with time/level/logger) in the console. If false, shows a simplified stamp with only the logger.</summary> + internal bool ShowFullStampInConsole { get; set; } + /// <summary>Whether to show trace messages in the console.</summary> internal bool ShowTraceInConsole { get; set; } @@ -124,7 +127,9 @@ namespace StardewModdingAPI.Framework { // generate message string levelStr = level.ToString().ToUpper().PadRight(Monitor.MaxLevelLength); - message = $"[{DateTime.Now:HH:mm:ss} {levelStr} {source}] {message}"; + + string fullMessage = $"[{DateTime.Now:HH:mm:ss} {levelStr} {source}] {message}"; + string consoleMessage = this.ShowFullStampInConsole ? fullMessage : $"[{source}] {message}"; // write to console if (this.WriteToConsole && (this.ShowTraceInConsole || level != LogLevel.Trace)) @@ -136,17 +141,17 @@ namespace StardewModdingAPI.Framework if (background.HasValue) Console.BackgroundColor = background.Value; Console.ForegroundColor = color; - Console.WriteLine(message); + Console.WriteLine(consoleMessage); Console.ResetColor(); } else - Console.WriteLine(message); + Console.WriteLine(consoleMessage); }); } // write to log file if (this.WriteToFile) - this.LogFile.WriteLine(message); + this.LogFile.WriteLine(fullMessage); } } } diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 70e53f5a..6a240a7b 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -346,6 +346,7 @@ namespace StardewModdingAPI if (this.Settings.DeveloperMode) { this.Monitor.ShowTraceInConsole = true; + this.Monitor.ShowFullStampInConsole = true; this.Monitor.Log($"You configured SMAPI to run in developer mode. The console may be much more verbose. You can disable developer mode by installing the non-developer version of SMAPI, or by editing {Constants.ApiConfigPath}.", LogLevel.Info); } if (!this.Settings.CheckForUpdates) @@ -864,7 +865,12 @@ namespace StardewModdingAPI /// <param name="name">The name of the module which will log messages with this instance.</param> private Monitor GetSecondaryMonitor(string name) { - return new Monitor(name, this.ConsoleManager, this.LogFile, this.CancellationTokenSource) { WriteToConsole = this.Monitor.WriteToConsole, ShowTraceInConsole = this.Settings.DeveloperMode }; + return new Monitor(name, this.ConsoleManager, this.LogFile, this.CancellationTokenSource) + { + WriteToConsole = this.Monitor.WriteToConsole, + ShowTraceInConsole = this.Settings.DeveloperMode, + ShowFullStampInConsole = this.Settings.DeveloperMode + }; } /// <summary>Get a human-readable name for the current platform.</summary> |