🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

Function weekly

Source
pub fn weekly(
    directory: impl AsRef<Path>,
    file_name_prefix: impl AsRef<Path>,
) -> RollingFileAppender ⓘ
Expand description

Creates a weekly-rotating file appender. The logs will rotate every Sunday at midnight UTC.

The appender returned by rolling::weekly can be used with non_blocking to create a non-blocking, weekly file appender.

A RollingFileAppender has a fixed rotation whose frequency is defined by Rotation. The directory and file_name_prefix arguments determine the location and file name’s prefix of the log file. RollingFileAppender automatically appends the current date in UTC.

§Examples

fn main () {
    let appender = tracing_appender::rolling::weekly("/some/path", "rolling.log");
    let (non_blocking_appender, _guard) = tracing_appender::non_blocking(appender);

    let collector = tracing_subscriber::fmt().with_writer(non_blocking_appender);

    tracing::collect::with_default(collector.finish(), || {
        tracing::event!(tracing::Level::INFO, "Hello");
    });
}

This will result in a log file located at /some/path/rolling.log.yyyy-MM-dd.