diff --git a/CHANGELOG.md b/CHANGELOG.md index 13f902c..397a48c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [1.1.1] - 2025-07-30 +- Logger: Added consistent padding formatting for the LogLevel field in logs so that all levels (e.g., INFO, FATAL) appear with equal width. +- Logger: Added a unit test to verify that the LogLevel in logs is always padded to 5 characters. + ## [1.1.0] - 2025-07-28 - Added `UIController.RemoveControl(string name)` to allow removing registered UserControls at runtime. - Documentation: Updated README with RemoveControl usage example in the UIController section. diff --git a/SerpentModding.Tests/UnitTest.cs b/SerpentModding.Tests/UnitTest.cs index d8585c6..bdd102e 100644 --- a/SerpentModding.Tests/UnitTest.cs +++ b/SerpentModding.Tests/UnitTest.cs @@ -94,6 +94,41 @@ public void Logger_GetLogFilePath_And_ReadAllLogs_BeforeInit() Assert.True(string.IsNullOrEmpty(path) || !File.Exists(path)); Assert.Empty(logs); } + + [Fact] + public void Logger_LogLevel_Padding_Is_Consistent() + { + var logger = Logger.Instance; + var logDir = Path.Combine(_tempLogDirectory, "PaddingTest"); + Directory.CreateDirectory(logDir); + logger.Initialize(LogLevel.Trace, logToConsole: false, logDirectory: logDir); + logger.Trace("TracePadding"); + logger.Debug("DebugPadding"); + logger.Info("InfoPadding"); + logger.Warn("WarnPadding"); + logger.Error("ErrorPadding"); + logger.Fatal("FatalPadding"); + var logs = logger.ReadAllLogs(); + foreach (var level in new[] { "TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL" }) + { + var padded = level.PadRight(5); + Assert.Contains(logs, l => l.Contains($"[{padded}]") ); + } + // Additionally: Each line with [LEVEL] must have 5 characters in the level field + foreach (var line in logs) + { + var start = line.IndexOf('[') + 1; + var end = line.IndexOf(']', start); + if (start > 0 && end > start && line.Length > end + 1 && line[end + 1] == ' ' && line[start - 1] == '[') + { + var maybeLevel = line.Substring(start, end - start); + if (new[] { "TRACE", "DEBUG", "INFO ", "WARN ", "ERROR", "FATAL" }.Contains(maybeLevel)) + { + Assert.Equal(5, maybeLevel.Length); + } + } + } + } } public class UIControllerTests : IDisposable diff --git a/SerpentModding/Logging.cs b/SerpentModding/Logging.cs index 1c7dd87..7553969 100644 --- a/SerpentModding/Logging.cs +++ b/SerpentModding/Logging.cs @@ -146,7 +146,8 @@ public void Log( var callerNamespace = GetCallingNamespace(); var className = Path.GetFileNameWithoutExtension(file ?? "UnknownClass"); var location = $"{className}.{caller}():{line}"; - var formatted = $"[{timestamp}] [{level.ToString().ToUpper()}] {{{callerNamespace}}} [{location}] {message}"; + var levelStr = level.ToString().ToUpper().PadRight(5); + var formatted = $"[{timestamp}] [{levelStr}] {{{callerNamespace}}} [{location}] {message}"; lock (_lock) { diff --git a/SerpentModding/Properties/AssemblyInfo.cs b/SerpentModding/Properties/AssemblyInfo.cs index 4347835..7ec45c6 100644 --- a/SerpentModding/Properties/AssemblyInfo.cs +++ b/SerpentModding/Properties/AssemblyInfo.cs @@ -7,7 +7,7 @@ [assembly: AssemblyCompany("SerpentModding")] [assembly: AssemblyCopyright("Copyright © 2025 SerpentModding")] [assembly: AssemblyConfiguration("Library")] -[assembly: AssemblyFileVersion("1.1.0")] -[assembly: AssemblyVersion("1.1.0")] +[assembly: AssemblyFileVersion("1.1.1")] +[assembly: AssemblyVersion("1.1.1")] [assembly: ComVisible(false)] [assembly: Guid("ac5ea1b1-c699-4f4d-bd77-86c697be00d8")]