Crates.io | durylog |
lib.rs | durylog |
version | 0.1.2 |
source | src |
created_at | 2023-01-17 17:24:33.696482 |
updated_at | 2023-01-20 08:57:27.606913 |
description | An easy to use library to implements logging on stdout, file or both. |
homepage | |
repository | https://github.com/durydevelop/rust-lib-durylog |
max_upload_size | |
id | 761116 |
size | 39,858 |
This crate adds logging to your projects or library.
After trying a lot of crates to make logging, I only found crates rich of futures but very complicate to use, or crates that are easy to use but log only on file or only on console.
I decided to write my own lib that aims to be easy to use with some usefull futures:
In file cargo.toml add:
[dependencies]
durylog = "0.1.0"
There are 2 way for use this crate:
let durylog=DLog::new();
and use like durylog.d("Log message");
DLog::new().init_logger().ok();
and use with log macro like debug!("Log message");
Read documentation and examples.
Output (on console and/or file) for default settings is like:
2023/01/02 18.01.27 : DEBUG : Debug message
First tag is datetime stamp, second tag is level name followed by log message tag
use durylog::DLog;
fn main() {
let durylog=DLog::new();
println!("{}", durylog.get_status()); // This prints all current crate settings (in this case are defaults)
durylog.e("Error message");
durylog.w("Warning message");
durylog.i("Info message");
durylog.d("Debug message");
durylog.t("Trace message");
}
This will log on stdout without colors.
use durylog::DLog;
fn main() {
let durylog=DLog::new()
.with_color() // Enable colors in console output (default disabled)
.widh_timestamp_format("%Y-%m-%d %H:%M:%S") // Change default timestamp
.widh_custom_separator(" | ") // Change default separator pattern for items
.with_file("durylog-custom.log").unwrap(); // Enable logging on file (default disable)
println!("{}", durylog.get_status()); // This prints all current crate settings (in this case there are custom)
durylog.e("Error message");
durylog.w("Warning message");
durlog.i("Info message");
durylog.d("Debug message");
durylog.t("Trace message");
}
This will log on stdout with colors, different formatting for timestamp and different tags separator and in file durylog-custom.log are added same log lines as in console.
use durylog::{error,warn,info,debug,trace,DLog};
fn main() {
DLog::new().init_logger().ok();
error!("Error message");
warn!("Warning message");
info!("Info message");
debug!("Debug message");
trace!("Trace message");
}
This will log on stdout without colors.
use durylog::{error,warn,info,debug,trace,DLog};
fn main() {
DLog::new()
.with_color() // Enable colors in console output (default disabled)
.widh_timestamp_format("%Y-%m-%d %H:%M:%S") // Change default timestamp
.widh_custom_separator(" | ") // Change default separator pattern for items
.with_file("log-custom.log").unwrap() // Enable logging on file (default disable)
.init_logger().ok();
error!("Error message");
warn!("Warning message");
info!("Info message");
debug!("Debug message");
trace!("Trace message");
}
This will log on stdout with colors, different formatting for timestamp and different tags separator and in file log-custom.log are added same log lines as in console.