Skip to content

Commit

Permalink
Merge pull request #6138 from peppy/logger-ensure-header-later
Browse files Browse the repository at this point in the history
Write log header later to ensure game identifiers are present
  • Loading branch information
bdach authored Jan 22, 2024
2 parents 4cfa451 + 8172b89 commit d7dd556
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions osu.Framework/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ private void add(string message = @"", LogLevel level = LogLevel.Verbose, Except
if (!Enabled || level < Level)
return;

ensureHeader();

logCount.Value++;

message = ApplyFilters(message);
Expand Down Expand Up @@ -394,6 +392,17 @@ private void writePendingLines()
using (var stream = Storage.GetStream(Filename, FileAccess.Write, FileMode.Append))
using (var writer = new StreamWriter(stream))
{
if (!headerAdded)
{
writer.WriteLine("----------------------------------------------------------");
writer.WriteLine($"{Name} Log for {UserIdentifier} (LogLevel: {Level})");
writer.WriteLine($"Running {GameIdentifier} {VersionIdentifier} on .NET {Environment.Version}");
writer.WriteLine($"Environment: {RuntimeInfo.OS} ({Environment.OSVersion}), {Environment.ProcessorCount} cores ");
writer.WriteLine("----------------------------------------------------------");

headerAdded = true;
}

foreach (string line in lines)
writer.WriteLine(line);
}
Expand Down Expand Up @@ -435,19 +444,6 @@ private static void cycleLogs()
}
}

private void ensureHeader()
{
if (headerAdded) return;

headerAdded = true;

add("----------------------------------------------------------", outputToListeners: false);
add($"{Name} Log for {UserIdentifier} (LogLevel: {Level})", outputToListeners: false);
add($"Running {GameIdentifier} {VersionIdentifier} on .NET {Environment.Version}", outputToListeners: false);
add($"Environment: {RuntimeInfo.OS} ({Environment.OSVersion}), {Environment.ProcessorCount} cores ", outputToListeners: false);
add("----------------------------------------------------------", outputToListeners: false);
}

private static readonly List<string> filters = new List<string>();
private static readonly Dictionary<string, Logger> static_loggers = new Dictionary<string, Logger>();

Expand Down

0 comments on commit d7dd556

Please sign in to comment.