tokio-rs / tracing

Application level tracing for Rust.
https://tracing.rs
MIT License
5.19k stars 677 forks source link

appender: add filter to limit and rotate log files by size #3026

Closed adrianbenavides closed 3 weeks ago

adrianbenavides commented 3 weeks ago

EDIT: after reviewing https://github.com/tokio-rs/tracing/pull/2497 in detail I decided to close this one. That PR has more or less what I expected from this feature, so I'll close this one to focus the attention on that PR. Apologies for the noise.

Motivation

The RollingFileAppender currently allows you to rotate the log files by time and limit the number of previous files kept on disk. In some environments where the disk capacity is limited, we also need to control and limit the size of the logs.

So far, two PR's have been submitted to add this feature: https://github.com/tokio-rs/tracing/pull/2904 and https://github.com/tokio-rs/tracing/pull/2497. Both try to add a new Rotation variant, forcing the user to choose between rotating by time or size, which can limit the UX depending on the needs of the user.

What I'd like ideally is to rotate logs on a frequency basis, but also limit the max size of a log file. The main goal though can be achieved with any of the 3 open PR's, which is having the ability to determine the max size of the logs of an application to get a better estimate of the host machine's disk requirements.

Closes https://github.com/tokio-rs/tracing/issues/1940 Closes https://github.com/tokio-rs/tracing/issues/858

Solution

This PR adds a new filter to limit the size of the logs files, which can be used together with the frequency rotation filter. The first condition to be met will decide how the file is rotated.