tracing-rolling 0.3.0

helper crate to customize rolling log file with tracing crate
Documentation
use std::{fs::File, sync::Mutex, time::Instant};

use time::macros::offset;
use tracing_rolling::{Checker, ConstFile, Daily};

fn main() {
    // 这里开启追加写和自动创建创建选项, 避免手动创建文件
    // 和覆盖之前的文件
    let log_file = File::options()
        .append(true)
        .create(true)
        .write(true)
        .open("logs/app.log")
        .unwrap();
    let (writer, token) = Daily::new("logs/testing.log", "[year][month][day]", offset!(+8))
        // Daily::new("logs/testing.log", None, offset!(+8))
        .buffer_with(8192) // buffer file if needed
        .build()
        .unwrap();

    let (c, tc) = ConstFile::new("logs/c.log")
        .buffer_with(8192)
        .build()
        .unwrap();
    tracing_subscriber::fmt()
        .with_ansi(false)
        // .with_writer(std::io::stdout)
        // .with_writer(log_file)
        // .with_writer(writer)
        .with_writer(c)
        .init();
    let now = Instant::now();
    let count = 1000000;
    for _ in 0..count {
        tracing::info!("all is well");
    }
    drop(tc);
    drop(token);
    eprintln!(
        "{:?} us/log",
        now.elapsed().as_micros() as f64 / (count as f64)
    );
}