Crates.io | tracing-rolling-file |
lib.rs | tracing-rolling-file |
version | 0.1.3 |
created_at | 2022-08-16 18:51:30.266056+00 |
updated_at | 2025-08-16 07:59:07.126791+00 |
description | A rolling file appender with customizable rolling conditions. |
homepage | https://github.com/cavivie/tracing-rolling-file |
repository | https://github.com/cavivie/tracing-rolling-file |
max_upload_size | |
id | 646875 |
size | 63,659 |
A rolling file appender with customizable rolling conditions, based on rolling-file. 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.
use tracing_rolling_file::*;
let file_appender = RollingFileAppenderBase::new(
"/var/log/myprogram",
RollingConditionBase::new().daily(),
9
).unwrap();
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("/var/log/myprogram"))
.max_filecount(10)
.condition_max_file_size(100)
.build()
.unwrap();
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();
Must pass latest stable clippy, be formatted with nightly rustfmt, and pass unit tests:
cargo +nightly fmt
cargo clippy --all-targets
cargo test
Dual-licensed under the terms of either the MIT license or the Apache 2.0 license.