daboross / fern

Simple, efficient logging for Rust
MIT License
848 stars 51 forks source link

rolling log file when reaches certain size #80

Open avnerbarr opened 3 years ago

avnerbarr commented 3 years ago

I saw a similar question about truncating log, but I want to create a new log file once reaches 20MB or some other metric (keeping the previous).

is there a way to achieve this?

cavivie commented 2 years ago

I also need this feature. Have you implemented this feature?

daboross commented 2 years ago

This hasn't been implemented, no. It wouldn't be the biggest change, but it hasn't been done!

To add this, we really just need to copy the DateBasedConfig implementation in log_impl.rs (https://github.com/daboross/fern/blob/main/src/log_impl.rs#L169-L261) and builders.rs (https://github.com/daboross/fern/blob/main/src/builders.rs#L541-L565), replacing DateBased with SizeBased and rotating in log_impl based on total size rather than date. A simple test like https://github.com/daboross/fern/blob/0ef6202750e9854e619b279a3ac33904bc5a82a4/examples/date-based-file-log.rs would be ideal too, but beyond that, just follow the compiler errors.

Tests as well would be ideal, but the base should be pretty simple. I've just not implemented that yet.