tracing-rolling-file 0.1.3

A rolling file appender with customizable rolling conditions.
Documentation

tracing-rolling-file

tracing-rolling-file on GitHub Actions tracing-rolling-file on crates.io tracing-rolling-file on docs.rs GitHub: cavivie/tracing-rolling-file license: MIT or Apache-2.0

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.

Examples

use tracing_rolling_file::*;
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("/var/log/myprogram"))
    .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();

Development

Must pass latest stable clippy, be formatted with nightly rustfmt, and pass unit tests:

cargo +nightly fmt
cargo clippy --all-targets
cargo test

License

Dual-licensed under the terms of either the MIT license or the Apache 2.0 license.