log_wrapper

Crates.iolog_wrapper
lib.rslog_wrapper
version0.1.1
sourcesrc
created_at2020-02-22 18:41:21.692068
updated_at2020-02-22 18:45:48.068304
descriptionJust some boilerplate code to a logger wrapper over the log crate that logs to STDOUT
homepage
repositoryhttps://github.com/nohupped/log_wrapper
max_upload_size
id211549
size17,128
0x80 (nohupped)

documentation

README

log_wrapper

docs crates.io

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.

Documentation

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

Why

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.

Commit count: 2

cargo fmt