diff options
author | Dan Volchek <volchek2@illinois.edu> | 2018-04-17 21:46:30 -0500 |
---|---|---|
committer | Dan Volchek <volchek2@illinois.edu> | 2018-04-17 21:46:30 -0500 |
commit | 73b75c628666f52120975ed70e572bba0e2810c3 (patch) | |
tree | ef87a2d1a1ec351899fb37ccd29cc14bd0681b45 /src | |
parent | bb2c52386015829c161a56d418f3795335559d8a (diff) | |
download | SMAPI-73b75c628666f52120975ed70e572bba0e2810c3.tar.gz SMAPI-73b75c628666f52120975ed70e572bba0e2810c3.tar.bz2 SMAPI-73b75c628666f52120975ed70e572bba0e2810c3.zip |
log user input to log file
Diffstat (limited to 'src')
-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 f70efb89..063707af 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -444,6 +444,9 @@ namespace StardewModdingAPI if (string.IsNullOrWhiteSpace(input)) continue; + // write input to log file + this.Monitor.LogUserInputToFile(input); + // parse input try { |