20 stable releases

Uses new Rust 2021

1.1.15 Nov 3, 2022
1.1.14 Mar 18, 2022
1.1.13 Apr 22, 2021
1.1.12 Jul 29, 2020
1.1.5 Nov 14, 2018

#77 in Debugging

Download history 5/week @ 2022-08-13 8/week @ 2022-08-20 23/week @ 2022-08-27 6/week @ 2022-09-03 26/week @ 2022-09-10 3/week @ 2022-09-17 10/week @ 2022-09-24 9/week @ 2022-10-01 8/week @ 2022-10-08 8/week @ 2022-10-15 5/week @ 2022-10-22 60/week @ 2022-10-29 11/week @ 2022-11-05 27/week @ 2022-11-12 24/week @ 2022-11-19 8/week @ 2022-11-26

82 downloads per month
Used in pipe-logger

MIT license

29KB
516 lines

Pipe Logger Lib

CI

Stores, rotates, compresses process logs.

Example

use pipe_logger_lib::*;

use std::fs;
use std::path::Path;

let test_folder = {
  let folder = Path::join(&Path::join(Path::new("tests"), Path::new("out")), "log-example");

  fs::remove_dir_all(&folder);

  fs::create_dir_all(&folder).unwrap();

  folder
};

let test_log_file = Path::join(&test_folder, Path::new("mylog.txt"));

let mut builder = PipeLoggerBuilder::new(&test_log_file);

builder
    .set_tee(Some(Tee::Stdout))
    .set_rotate(Some(RotateMethod::FileSize(30))) // bytes
    .set_count(Some(10))
    .set_compress(false);

{
    let mut logger = builder.build().unwrap();

    logger.write_line("Hello world!").unwrap();

    let rotated_log_file_1 = logger.write_line("This is a convenient logger.").unwrap().unwrap();

    logger.write_line("Other logs...").unwrap();
    logger.write_line("Other logs...").unwrap();

    let rotated_log_file_2 = logger.write_line("Rotate again!").unwrap().unwrap();

    logger.write_line("Ops!").unwrap();
}

fs::remove_dir_all(test_folder).unwrap();

Now, the contents of test_log_file are,

Ops!

The contents of rotated_log_file_1 are,

Hello world!
This is a convenient logger.

The contents of rotated_log_file_2 are,

Other logs...
Other logs...
Rotate again!

Crates.io

https://crates.io/crates/pipe-logger-lib

Documentation

https://docs.rs/pipe-logger-lib

Official CLI

https://crates.io/crates/pipe-logger

License

MIT

Dependencies

~3.5MB
~82K SLoC