Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
35 changes: 35 additions & 0 deletions SerpentModding.Tests/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion SerpentModding/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions SerpentModding/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]