#logging #rotating #rotation #logrotate

rotating-file

A thread-safe rotating file with customizable rotation behavior

9 releases

0.3.6 Apr 16, 2022
0.3.5 Jan 18, 2021
0.2.0 Jan 17, 2021
0.1.0 Jan 17, 2021

#301 in Compression

31 downloads per month

Apache-2.0

19KB
411 lines

rotating-file

A thread-safe rotating file with customizable rotation behavior.

Example

use rotating_file::RotatingFile;

fn main() {
    let root_dir = "./target/tmp";
    let s = "The quick brown fox jumps over the lazy dog";

    // rotated by 1 kilobyte, compressed with gzip
    let rotating_file = RotatingFile::new(root_dir, Some(1), None, None, None, None, None);
    for _ in 0..24 {
        rotating_file.writeln(s).unwrap();
    }
    rotating_file.close();

    assert_eq!(2, std::fs::read_dir(root_dir).unwrap().count());
    std::fs::remove_dir_all(root_dir).unwrap();
}

lib.rs:

A thread-safe rotating file with customizable rotation behavior.

Example

use rotating_file::RotatingFile;

let root_dir = "./target/tmp";
let s = "The quick brown fox jumps over the lazy dog";
let _ = std::fs::remove_dir_all(root_dir);

// rotated by 1 kilobyte, compressed with gzip
let rotating_file = RotatingFile::new(root_dir, Some(1), None, None, None, None, None);
for _ in 0..24 {
    rotating_file.writeln(s).unwrap();
}
rotating_file.close();

assert_eq!(2, std::fs::read_dir(root_dir).unwrap().count());
std::fs::remove_dir_all(root_dir).unwrap();

Dependencies

~6.5MB
~106K SLoC