diff options
author | atravita-mods <94934860+atravita-mods@users.noreply.github.com> | 2022-08-15 19:13:24 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-10-08 13:27:04 -0400 |
commit | 7c90385d8df7bbf9469fc468480b26ebb134abd8 (patch) | |
tree | d106384036e9607eb963ccf4093036121e92c4bb | |
parent | e7d29a2f7dabde75fb1ad76af1975c9194b1b8bd (diff) | |
download | SMAPI-7c90385d8df7bbf9469fc468480b26ebb134abd8.tar.gz SMAPI-7c90385d8df7bbf9469fc468480b26ebb134abd8.tar.bz2 SMAPI-7c90385d8df7bbf9469fc468480b26ebb134abd8.zip |
Pre-calculate the strings for log levels.
-rw-r--r-- | src/SMAPI/Framework/Monitor.cs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/Monitor.cs b/src/SMAPI/Framework/Monitor.cs index 6b53daff..8ba175e6 100644 --- a/src/SMAPI/Framework/Monitor.cs +++ b/src/SMAPI/Framework/Monitor.cs @@ -25,7 +25,9 @@ namespace StardewModdingAPI.Framework private readonly LogFileManager LogFile; /// <summary>The maximum length of the <see cref="LogLevel"/> values.</summary> - private static readonly int MaxLevelLength = (from level in Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>() select level.ToString().Length).Max(); + private static readonly int MaxLevelLength = (from level in Enum.GetValues<LogLevel>() select level.ToString().Length).Max(); + + private static readonly Dictionary<ConsoleLogLevel, string> LogStrings = Enum.GetValues<ConsoleLogLevel>().ToDictionary(k => k, v => v.ToString().ToUpper().PadRight(MaxLevelLength)); /// <summary>A cache of messages that should only be logged once.</summary> private readonly HashSet<string> LogOnceCache = new(); @@ -147,7 +149,7 @@ namespace StardewModdingAPI.Framework /// <param name="level">The log level.</param> private string GenerateMessagePrefix(string source, ConsoleLogLevel level) { - string levelStr = level.ToString().ToUpper().PadRight(Monitor.MaxLevelLength); + string levelStr = LogStrings[level]; int? playerIndex = this.GetScreenIdForLog(); return $"[{DateTime.Now:HH:mm:ss} {levelStr}{(playerIndex != null ? $" screen_{playerIndex}" : "")} {source}]"; |