Crates.io | log-wrap |
lib.rs | log-wrap |
version | 0.1.0 |
source | src |
created_at | 2023-01-08 08:06:02.635941 |
updated_at | 2023-01-08 08:06:02.635941 |
description | Utilities for log by wrapping `Box |
homepage | |
repository | |
max_upload_size | |
id | 753522 |
size | 8,211 |
Utilities for log by wrapping Box<dyn log::Log>
, such as log filtering, log capturing
filter log by module name
fn main() {
std::env::set_var("RUST_LOG", "info");
let logger = env_logger::Builder::from_default_env().build();
log::set_max_level(logger.filter());
log_wrap::LogWrap::new(Box::new(logger))
.black_module(["hyper", "h2"])
.init()
.unwrap();
// your code ...
}
capturing logs in each thread, and output them synchronously before thread exiting
fn main() {
std::env::set_var("RUST_LOG", "info");
let logger = env_logger::Builder::from_default_env().build();
log::set_max_level(logger.filter());
log_wrap::LogWrap::new(Box::new(logger))
.enable_thread_capture()
.init()
.unwrap();
let joins = (0..5)
.map(|t| {
std::thread::spawn(move || {
let _guard = log_wrap::capture_thread_log();
for i in 0..5 {
log::info!("thread#{t} {i} ...");
}
})
})
.collect::<Vec<_>>();
for j in joins {
j.join().unwrap()
}
}