Crates.io | logs |
lib.rs | logs |
version | 0.7.1 |
source | src |
created_at | 2020-07-06 09:02:41.98971 |
updated_at | 2022-11-10 09:36:34.439676 |
description | A simple terminal logger |
homepage | https://github.com/wyhaya/logs |
repository | https://github.com/wyhaya/logs.git |
max_upload_size | |
id | 261889 |
size | 10,726 |
A simple terminal logger
Add this in your Cargo.toml
:
[dependencies]
logs = "*"
use logs::{debug, error, info, trace, warn, Logs};
fn main() {
Logs::new().init();
trace!("This is a trace log");
debug!("This is a debug log");
info!("This is a info log");
warn!("This is a warn log");
error!("This is a error log");
}
Output:
2022-09-06T08:38:23.490 [TRACE] This is a trace log
2022-09-06T08:38:23.490 [DEBUG] This is a debug log
2022-09-06T08:38:23.490 [INFO ] This is a info log
2022-09-06T08:38:23.490 [WARN ] This is a warn log
2022-09-06T08:38:23.490 [ERROR] This is a error log
use logs::{Logs, debug, error, LevelFilter};
fn main() {
Logs::new()
// Show log level color
.color(true)
// Filter log target
.target("target")
// Filter log level
.level(LevelFilter::Info)
// Filter log target from `LOG` environment variable
.level_from_default_env()
.unwrap()
// Filter log target from `NAME` environment variable
.level_from_env("NAME")
.unwrap()
// Filter log level from str
.level_from_str("info")
.unwrap()
// Apply
.init();
}