Implement native size/time log rotation with gzip compression#189
Implement native size/time log rotation with gzip compression#189Anyitechs wants to merge 1 commit intolightningdevkit:mainfrom
Conversation
|
🎉 This PR is now ready for review! |
|
I would rather keep the old version. I like all the handling for the different signals in |
Update the ServerLogger to track file size and age internally, triggering rotation at 50MB or 24 hours. Old logs are now compressed in the background using native OS gzip via `std::thread::spawn`, eliminating the need for the user to configure `logrotate`. Disk writes are also now buffered for better runtime performance. Co-Authored-By: Gemini 3.0 Pro
As we discussed elsewhere, this is now dropped entirely as we're moving to doing the rotation ourselves rather than relying on the user to configure |
|
🔔 1st Reminder Hey @benthecarman! This PR has been waiting for your review. |
| /// Maximum size of the log file before it gets rotated (50 MB) | ||
| const MAX_LOG_SIZE_BYTES: usize = 50 * 1024 * 1024; | ||
| /// Maximum age of the log file before it gets rotated (24 hours) | ||
| const ROTATION_INTERVAL_SECS: u64 = 24 * 60 * 60; |
There was a problem hiding this comment.
these should be configurable
| state.created_at = SystemTime::now(); | ||
|
|
||
| // Spawn independent OS thread to compress the old file using native gzip | ||
| thread::spawn(move || match Command::new("gzip").arg("-f").arg(&rotated_path).status() { |
There was a problem hiding this comment.
This is assuming they have gzip installed and we have permissions to run it. I would rather just have the rust code do this
There was a problem hiding this comment.
It doesn't really seem worth taking a gzip dependency just to do log rotation. We can just rotate and delete as-is and tell people to use the system log (which handles this properly) otherwise. Really we shouldn't be doing logging ourselves anyway - log should go to stdout/err and systemd or some other logic should figure out what to do with it.
There was a problem hiding this comment.
I'm happy to drop the compression so we do a rotate and delete. If that works for everyone, I'll update this to introduce a configurable max_rotated_files that will default to the last 5 uncompressed files. Does that work?
There was a problem hiding this comment.
I'm in favor of just doing deletion instead of compression but I would really rather keep the log file and not rely on just stdout/stderr. If we don't have an easy log file and rely on the user's systemd/docker/whatever to do and persist the logs, we will likely not have logs for lots of users and make it much harder to do support.
This updates the
ServerLoggerto track file size and age internally, triggering rotation at 50MB or 24 hours. Old logs are now compressed in the background using native OSgzipviastd::thread::spawn, eliminating the need for the user to configurelogrotate.Disk writes are also now buffered for better runtime performance.