File: rotate.rs

package info (click to toggle)
rust-flexi-logger 0.29.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,084 kB
  • sloc: makefile: 2
file content (28 lines) | stat: -rw-r--r-- 757 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use flexi_logger::{
    Age, Cleanup, Criterion, Duplicate, FileSpec, FlexiLoggerError, LevelFilter, Logger, Naming,
};
use std::{thread::sleep, time::Duration};

fn main() -> Result<(), FlexiLoggerError> {
    Logger::with(LevelFilter::Info)
        .rotate(
            Criterion::Age(Age::Second),
            Naming::TimestampsCustomFormat {
                current_infix: None,
                format: "%Y%m%d_%H%M%S",
            },
            Cleanup::Never,
        )
        .log_to_file(FileSpec::default())
        .duplicate_to_stdout(Duplicate::All)
        .start()?;

    log::info!("start");
    for step in 0..10 {
        log::info!("step {}", step);
        sleep(Duration::from_millis(250));
    }
    log::info!("done");

    Ok(())
}