summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/Monitor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework/Monitor.cs')
-rw-r--r--src/SMAPI/Framework/Monitor.cs32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/SMAPI/Framework/Monitor.cs b/src/SMAPI/Framework/Monitor.cs
index a76afc3c..cc511ed4 100644
--- a/src/SMAPI/Framework/Monitor.cs
+++ b/src/SMAPI/Framework/Monitor.cs
@@ -48,9 +48,6 @@ namespace StardewModdingAPI.Framework
/// <summary>Whether to write anything to the console. This should be disabled if no console is available.</summary>
internal bool WriteToConsole { get; set; } = true;
- /// <summary>Whether to write anything to the log file. This should almost always be enabled.</summary>
- internal bool WriteToFile { get; set; } = true;
-
/*********
** Public methods
@@ -96,8 +93,16 @@ namespace StardewModdingAPI.Framework
{
if (this.WriteToConsole)
this.ConsoleManager.ExclusiveWriteWithoutInterception(Console.WriteLine);
- if (this.WriteToFile)
- this.LogFile.WriteLine("");
+ this.LogFile.WriteLine("");
+ }
+
+ /// <summary>Log console input from the user.</summary>
+ /// <param name="input">The user input to log.</param>
+ internal void LogUserInput(string input)
+ {
+ // user input already appears in the console, so just need to write to file
+ string prefix = this.GenerateMessagePrefix(this.Source, LogLevel.Info);
+ this.LogFile.WriteLine($"{prefix} $>{input}");
}
@@ -120,9 +125,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
@@ -144,8 +148,16 @@ namespace StardewModdingAPI.Framework
}
// write to log file
- if (this.WriteToFile)
- this.LogFile.WriteLine(fullMessage);
+ this.LogFile.WriteLine(fullMessage);
+ }
+
+ /// <summary>Generate 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>