d_logger 0.1.0

A simple logger
Documentation
  • Coverage
  • 80%
    4 out of 5 items documented4 out of 4 items with examples
  • Size
  • Source code size: 21.29 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 368.02 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 21s Average build duration of successful builds.
  • all releases: 21s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • DawsonThePagan/d_logger
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • DawsonThePagan

d_logger

A rust crate providing simple logging with a dated clean up util.

Examples

Create a logger with 7 days of cleaning

use d_logger::Logger;

let logger = Logger::new("C:/logs/".to_string(), "Log%d%m%y.log".to_string(), "%Y-%m-%d %H:%M:%S".to_string(), Some(7)).unwrap();
if !logger.write_log("This is a test log entry") {
    panic!("Logger failed");
}
// This will work
logger.log_clean(None);

Create a logger without any cleaning

use d_logger::Logger;

let logger = Logger::new("C:/logs/".to_string(), "Log%d%m%y.log".to_string(), "%Y-%m-%d %H:%M:%S".to_string(), None).unwrap();
if !logger.write_log("This is a test log entry") {
    panic!("Logger failed");
}
// This will fail
logger.log_clean(None);

Clean logs with a regex filter

use d_logger::Logger;

let logger = Logger::new("C:/logs/".to_string(), "Log%d%m%y.log".to_string(), "%Y-%m-%d %H:%M:%S".to_string(), Some(7)).unwrap();
if !logger.write_log("This is a test log entry") {
    panic!("Logger failed");
}
// This will work
logger.log_clean(Some(r"example_test_\d{8}.log"));

Functions

new(path: String, file_name_format: String, line_date_format: String, days_keep: Option) -> Result<Logger, io::error>

Create a new logging structure and test that the path and file given can be accessed.

write_log(line: String) -> bool

Write a line to the log file. Will return whether its successful

log_clean(regex: Option<&str>)

Clean up the log directory. If regex is provided only files matching regex will be deleted. Will only delete anything if days_keep was set. The files delete must be older than the number of days wanted to keep.