tracing icon indicating copy to clipboard operation
tracing copied to clipboard

Size rolling

Open x3ccd4828 opened this issue 5 months ago • 0 comments

This patch adds size-based rotation to tracing-appender.

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

cc @hawkw @IniterWorker @CfirTsabari @davidbarsky @CBenoit

There is another pull request (https://github.com/tokio-rs/tracing/pull/2497) for this feature but I thought I would try a different approach.

Motivation

In a constrained environment, we should be able to constrain the logging size and period.

Solution

Maximum bytes per log file may be specified in the max_file_size function when building the appender. The option will only be used when selecting Rotation::SIZE.

File size is checked every write and if the size is exceeded the log file is rolled over.

None of the other rotation types use sub-seconds in the logfile name but for size-based rotation, I used it since there could be a plethora of writes in a short period and this was the simple way to ensure filename uniqueness otherwise it would write to the same file even if the size was exceeded. This is a limitation since I tried to use the same methodology as the time-based rolling without rewriting the architecture.

x3ccd4828 avatar Mar 07 '24 18:03 x3ccd4828