#logger #log #pipe #rotation #logrotate

pipe-logger-lib

Stores, rotates, compresses process logs

18 stable releases

1.1.13 Apr 22, 2021
1.1.12 Jul 29, 2020
1.1.11 Jun 27, 2020
1.1.8 Feb 27, 2020
1.1.5 Nov 14, 2018

#59 in Debugging

Download history 34/week @ 2021-08-11 41/week @ 2021-08-18 13/week @ 2021-08-25 23/week @ 2021-09-01 37/week @ 2021-09-08 10/week @ 2021-09-15 18/week @ 2021-09-22 29/week @ 2021-09-29 77/week @ 2021-10-06 93/week @ 2021-10-13 36/week @ 2021-10-20 32/week @ 2021-10-27 56/week @ 2021-11-03 18/week @ 2021-11-10 11/week @ 2021-11-17 6/week @ 2021-11-24

114 downloads per month
Used in pipe-logger

MIT license

29KB
520 lines

Pipe Logger Lib

CI

Stores, rotates, compresses process logs.

Example

extern crate pipe_logger_lib;

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
~79K SLoC