-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write log header later to ensure game identifiers are present #6138
Conversation
c3a301c
to
fde229c
Compare
Is there any particular reason for that? Not that I necessarily care very much, but it just reads like a non-sequitur compared to the rest of the OP. I don't see why that measure would need to be taken. |
I can add it back, but if you check the code it should be apparently why they aren't there (different code path now). It would look something like this: diff --git a/osu.Framework/Logging/Logger.cs b/osu.Framework/Logging/Logger.cs
index 32731b801..63dddb504 100644
--- a/osu.Framework/Logging/Logger.cs
+++ b/osu.Framework/Logging/Logger.cs
@@ -315,7 +315,7 @@ private void add(string message = @"", LogLevel level = LogLevel.Verbose, Except
IEnumerable<string> lines = logOutput
.Replace(@"\r\n", @"\n")
.Split('\n')
- .Select(s => $@"{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)} [{level.ToString().ToLowerInvariant()}]: {s.Trim()}");
+ .Select(l => addTimestamp(l, level));
if (outputToListeners)
{
@@ -394,11 +394,16 @@ private void writePendingLines()
{
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("----------------------------------------------------------");
+ lines = new[]
+ {
+ "----------------------------------------------------------",
+ $"{Name} Log for {UserIdentifier} (LogLevel: {Level})",
+ $"Running {GameIdentifier} {VersionIdentifier} on .NET {Environment.Version}",
+ $"Environment: {RuntimeInfo.OS} ({Environment.OSVersion}), {Environment.ProcessorCount} cores ",
+ "----------------------------------------------------------"
+ }
+ .Select(l => addTimestamp(l, Level))
+ .Concat(lines).ToArray();
headerAdded = true;
}
@@ -412,6 +417,11 @@ private void writePendingLines()
}
}
+ private string addTimestamp(string s, LogLevel level)
+ {
+ return $@"{DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)} [{level.ToString().ToLowerInvariant()}]: {s.Trim()}";
+ }
+
/// <summary>
/// Whether the output of this logger should be sent to listeners of <see cref="Debug"/> and <see cref="Console"/>.
/// Defaults to true.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems fine
The flow in
GameHost
ensures that the game/version identifiers are set beforeLogger.Storage
is set. Unfortunately, until now any call to the staticLogger.Log
would immediately materialise the headers into their final string form. A stray log call beforeGameHost.Run
could result in less-than-optimal headers.This can be seen in osu!'s runtime log from an early log call.
Before:
After:
Note that timestamps are not prefixed to the header now, but I think this is probably for the best.