diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-04-25 11:58:34 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-25 11:58:34 -0400 |
commit | da66a3ef8eaabf79c26ba8e8e5c8a817560f2c6d (patch) | |
tree | 99720e7c9413ed978625e02db62054daa3037c04 | |
parent | 151789caa98025632048a1a2d7feb3b64c70829e (diff) | |
parent | 73b75c628666f52120975ed70e572bba0e2810c3 (diff) | |
download | SMAPI-da66a3ef8eaabf79c26ba8e8e5c8a817560f2c6d.tar.gz SMAPI-da66a3ef8eaabf79c26ba8e8e5c8a817560f2c6d.tar.bz2 SMAPI-da66a3ef8eaabf79c26ba8e8e5c8a817560f2c6d.zip |
Merge pull request #475 from danvolchek/logcommands
Log user input to logfile
-rw-r--r-- | src/SMAPI/Framework/Monitor.cs | 25 | ||||
-rw-r--r-- | src/SMAPI/Program.cs | 3 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/SMAPI/Framework/Monitor.cs b/src/SMAPI/Framework/Monitor.cs index a76afc3c..b65932b2 100644 --- a/src/SMAPI/Framework/Monitor.cs +++ b/src/SMAPI/Framework/Monitor.cs @@ -100,6 +100,17 @@ namespace StardewModdingAPI.Framework this.LogFile.WriteLine(""); } + /// <summary>Writes user input to the log file.</summary> + /// <param name="input">The input to write.</param> + internal void LogUserInputToFile(string input) + { + if (this.WriteToFile) + { + string prefix = this.GenerateMessagePrefix(this.Source, LogLevel.Info); + this.LogFile.WriteLine($"{prefix} $>{input}"); + } + } + /********* ** Private methods @@ -120,9 +131,8 @@ namespace StardewModdingAPI.Framework private void LogImpl(string source, string message, LogLevel level, ConsoleColor color, ConsoleColor? background = null) { // generate message - string levelStr = level.ToString().ToUpper().PadRight(Monitor.MaxLevelLength); - - string fullMessage = $"[{DateTime.Now:HH:mm:ss} {levelStr} {source}] {message}"; + string prefix = this.GenerateMessagePrefix(source, level); + string fullMessage = $"{prefix} {message}"; string consoleMessage = this.ShowFullStampInConsole ? fullMessage : $"[{source}] {message}"; // write to console @@ -148,6 +158,15 @@ namespace StardewModdingAPI.Framework this.LogFile.WriteLine(fullMessage); } + /// <summary>Generates a message prefix for the current time.</summary> + /// <param name="source">The name of the mod logging the message.</param> + /// <param name="level">The log level.</param> + private string GenerateMessagePrefix(string source, LogLevel level) + { + string levelStr = level.ToString().ToUpper().PadRight(Monitor.MaxLevelLength); + return $"[{DateTime.Now:HH:mm:ss} {levelStr} {source}]"; + } + /// <summary>Get the color scheme to use for the current console.</summary> /// <param name="colorScheme">The console color scheme to use.</param> private static IDictionary<LogLevel, ConsoleColor> GetConsoleColorScheme(MonitorColorScheme colorScheme) diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 9789cf85..73e8bb07 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -448,6 +448,9 @@ namespace StardewModdingAPI if (string.IsNullOrWhiteSpace(input)) continue; + // write input to log file + this.Monitor.LogUserInputToFile(input); + // parse input try { |