Crates.io | log_wrapper |
lib.rs | log_wrapper |
version | 0.1.1 |
source | src |
created_at | 2020-02-22 18:41:21.692068 |
updated_at | 2020-02-22 18:45:48.068304 |
description | Just some boilerplate code to a logger wrapper over the log crate that logs to STDOUT |
homepage | |
repository | https://github.com/nohupped/log_wrapper |
max_upload_size | |
id | 211549 |
size | 17,128 |
Just some boilerplate code for a logger wrapped over the log crate that logs to STDOUT. This has a global static ConsoleLogger
struct that over-rides the log::Log
trait. Once this is initiated with the ConsoleLogger::new(loglevel)
, where loglevel is either of trace, debug, info, warn, error, off
, the standard macros from log
crate such as info!
, warn!
, etc. can be used to print and the output will be filtered as per the defined loglevel.
Eg:
somemod/src/main.rc
#[macro_use]
extern crate log;
use log_wrapper::{ConsoleLogger};
use somemod_backend::print_log;
fn main() {
ConsoleLogger::new("warn".to_string());
info!("This is info");
warn!("warning");
error!("oops");
println!("Now from module");
print_log();
}
somemod_backend/src/lib.rs
#[macro_use]
extern crate log;
pub mod nested_mod{
pub fn print_log() {
info!("This is info");
warn!("warning");
error!("oops");
}
}
Output:
23/02/2020:02:29:10 WARN module:somemod file:somemod/src/main.rs:8 warning
23/02/2020:02:29:10 ERROR module:somemod file:somemod/src/main.rs:9 oops
Now from module
23/02/2020:02:29:10 WARN module:somemod_backend::nested_mod file:somemod_backend/src/lib.rs:6 warning
23/02/2020:02:29:10 ERROR module:somemod_backend::nested_mod file:somemod_backend/src/lib.rs:7 oops
This is just the boilerplate code taken from the log crate itself that I wanted to use so that I don't have to type it every time.