| Crates.io | d_logger |
| lib.rs | d_logger |
| version | 0.1.0 |
| created_at | 2025-04-23 11:09:41.255162+00 |
| updated_at | 2025-04-23 11:09:41.255162+00 |
| description | A simple logger |
| homepage | |
| repository | https://github.com/DawsonThePagan/d_logger |
| max_upload_size | |
| id | 1645382 |
| size | 21,290 |
A rust crate providing simple logging with a dated clean up util.
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"));
Create a new logging structure and test that the path and file given can be accessed.
Write a line to the log file. Will return whether its successful
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.