Skip to content

Implement native size/time log rotation with gzip compression#189

Open
Anyitechs wants to merge 1 commit intolightningdevkit:mainfrom
Anyitechs:log-rotation
Open

Implement native size/time log rotation with gzip compression#189
Anyitechs wants to merge 1 commit intolightningdevkit:mainfrom
Anyitechs:log-rotation

Conversation

@Anyitechs
Copy link
Copy Markdown
Contributor

@Anyitechs Anyitechs commented Apr 15, 2026

This updates 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.

@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Apr 15, 2026

🎉 This PR is now ready for review!
Please choose at least one reviewer by assigning them on the right bar.
If no reviewers are assigned within 10 minutes, I'll automatically assign one.
Once the first reviewer has submitted a review, a second will be assigned if required.

@Anyitechs Anyitechs marked this pull request as draft April 15, 2026 19:35
@benthecarman
Copy link
Copy Markdown
Collaborator

I would rather keep the old version. I like all the handling for the different signals in main.rs, makes things easier to reason about imo.

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
@Anyitechs Anyitechs changed the title refactor: encapsulate log rotation logic Implement native size/time log rotation with gzip compression Apr 17, 2026
@Anyitechs Anyitechs marked this pull request as ready for review April 17, 2026 19:58
@Anyitechs
Copy link
Copy Markdown
Contributor Author

I would rather keep the old version. I like all the handling for the different signals in main.rs, makes things easier to reason about imo.

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 logrotate.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 1st Reminder

Hey @benthecarman! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Comment on lines +20 to +23
/// 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;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is assuming they have gzip installed and we have permissions to run it. I would rather just have the rust code do this

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants