-
Notifications
You must be signed in to change notification settings - Fork 425
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
Add a session timestamp prefix to log files (and retain 7 days of logs) #6063
Conversation
Keeping this would cause the header to be output multiple times.
@@ -65,8 +73,7 @@ public static Storage Storage | |||
{ | |||
storage = value ?? throw new ArgumentNullException(nameof(value)); | |||
|
|||
// clear static loggers so they are correctly purged at the new storage location. | |||
static_loggers.Clear(); |
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.
Just noting this: changing the logger storage when the game is running will no longer write the logger header to the new log files.
Changing the logger storage during runtime is dubious, and the old code is incorrect since it wasn't locking flush_sync_lock
when accessing a thread-shared resource (static_loggers
).
So I'm not against this change. Maybe change the setter to internal
to reflect that we don't support changing the storage.
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.
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.
On second thoughts, I guess this depends on what we consider the log header to be. Should it signal the start of a session and therefore not be present on a partial log? I could imagine this being one correct way of looking at it.
Here's a diff to make the log header output correctly after storage changes only, in case that is the preferred direction:
diff --git a/osu.Framework/Logging/Logger.cs b/osu.Framework/Logging/Logger.cs
index fb7301901..ea492be99 100644
--- a/osu.Framework/Logging/Logger.cs
+++ b/osu.Framework/Logging/Logger.cs
@@ -63,6 +63,8 @@ public class Logger
private static Storage storage;
+ private static string storageFullPath = string.Empty;
+
/// <summary>
/// The storage to place logs inside.
/// </summary>
@@ -71,8 +73,20 @@ public static Storage Storage
private get => storage;
set
{
+ if (storage == value)
+ return;
+
storage = value ?? throw new ArgumentNullException(nameof(value));
+ string newPath = storage.GetFullPath(string.Empty);
+
+ // If the full path has changed, recreate loggers to correctly purge and
+ // repopulate the log's header.
+ if (newPath == storageFullPath)
+ static_loggers.Clear();
+
+ storageFullPath = newPath;
+
cycleLogs();
}
}
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.
I consider it as the start of a session, but I wouldn't mind it being output every time.
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.
I think I'd rather it didn't output every time so we know that some logs might be missing from the start.
osu.Framework/Logging/Logger.cs
Outdated
{ | ||
scheduler.Add(() => | ||
DateTime logCycleCutoff = DateTime.UtcNow.AddDays(-7); | ||
var logFiles = new DirectoryInfo(storage.GetFullPath(string.Empty)).GetFiles(); |
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.
A bit worried about this, in-case storage is set incorrectly it could nuke unrelated files.
How about doing additional checks against the filename? Something like making sure it matches *.{Name}.log
?
@@ -65,8 +73,7 @@ public static Storage Storage | |||
{ | |||
storage = value ?? throw new ArgumentNullException(nameof(value)); | |||
|
|||
// clear static loggers so they are correctly purged at the new storage location. | |||
static_loggers.Clear(); |
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.
I consider it as the start of a session, but I wouldn't mind it being output every time.
Will be useful for diagnosing user issues where they already restarted the game and as a consequence, nuked previous logs.