daboross/fern

rolling log file when reaches certain size

avnerbarr opened this issue · 2 comments

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?

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

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.