Rust Logging Optimization: Implementing Daily Rotation and File Size Limits
Background
In Rust, the default tracing strategy writes logs to standard output with no size limit.
But in a real production environment, we need logs written to a file, with the size capped and a new file rolled out every day.
Implementation
I checked the tracing docs and found it can only control the rotation period, not the output size.
tracing_appender rolling
</br>
use tracing_appender::rolling::Rotation;
let rotation = tracing_appender::rolling::Rotation::DAILY;
let file_appender = BasicRollingFileAppender::new(
"/var/log/myprogram",
RollingConditionBasic::new().daily(),
9
).unwrap();
let (non_blocking_appender, _guard) = non_blocking(file_appender);