Expand description
A rolling file appender with customizable rolling conditions. Includes built-in support for rolling conditions on date/time (daily, hourly, every minute) and/or size.
Follows a Debian-style naming convention for logfiles, using basename, basename.1, …, basename.N where N is the maximum number of allowed historical logfiles.
This is useful to combine with the tracing crate and tracing_appender::non_blocking::NonBlocking – use it as an alternative to tracing_appender::rolling::RollingFileAppender.
§Examples
let file_appender = RollingFileAppenderBase::new(
"/var/log/myprogram",
RollingConditionBase::new().daily(),
9
).unwrap();
§Builder
To simplify the creation of a RollingFileAppenderBase
, an instance can be built as per the example below.
use tracing_rolling_file::*;
let builder = RollingFileAppenderBase::builder();
let appender = builder
.filename(String::from("my_app.log"))
.max_filecount(10)
.condition_max_file_size(100)
.build()
.unwrap();
§Non-blocking support
To combine the tracing_appender::non_blocking::NonBlocking
functionality,
the feature needs to be enabled in Cargo.toml, i.e.
[dependencies]
tracing-rolling-file = { version = "0.1.3", features = ["non-blocking"] }
Once enabled, you can use the method get_non_blocking_appender
to generate
a non-blocking version of the RollingFileAppenderBase.
use tracing_rolling_file::*;
let file_appender = RollingFileAppenderBase::new(
"/var/log/myprogram",
RollingConditionBase::new().daily(),
9
)?;
let (non_blocking, _guard) = file_appender.get_non_blocking_appender();
Re-exports§
pub use base::*;
Modules§
- base
- Implements a rolling condition based on a certain frequency and/or a size limit. The default condition is to rotate daily.
Structs§
- Rolling
File Appender - Writes data to a file, and “rolls over” to preserve older data in a separate set of files. Old files have a Debian-style naming scheme where we have base_filename, base_filename.1, …, base_filename.N where N is the maximum number of rollover files to keep.
Enums§
- Rolling
Frequency - Determines how often a file should be rolled over
Traits§
- Rolling
Condition - Determines when a file should be “rolled over”.