#log #settings

log_settings

a tiny crate allowing libraries to change logger settings

2 releases

0.1.1 May 31, 2016
0.1.0 May 31, 2016

#5 in Debugging

Download history 5189/week @ 2018-05-27 6493/week @ 2018-06-03 6310/week @ 2018-06-10 5211/week @ 2018-06-17 5505/week @ 2018-06-24 6994/week @ 2018-07-01 6414/week @ 2018-07-08 7277/week @ 2018-07-15 7598/week @ 2018-07-22 6306/week @ 2018-07-29 7173/week @ 2018-08-05 7079/week @ 2018-08-12 6723/week @ 2018-08-19

22,555 downloads per month
Used in 1 crate

MIT license

4KB


lib.rs:

This crate enables libraries that use the log crate (or an equivalent) to communicate with the actual logger, without requiring the library to know about the type of logger that is used. The crate

On the library side

You can set a value by accessing the Settings struct through the settings function.

extern crate log_settings;
log_settings::settings().indentation += 1;

On the executable side

You can read a value by accessing the Settings struct through the settings function.

#[macro_use] extern crate log;
extern crate env_logger;
extern crate log_settings;

use std::env;
use log::{LogRecord, LogLevelFilter};
use env_logger::LogBuilder;

fn main() {
    let format = |record: &LogRecord| {
        // prepend spaces to indent the final string
        let indentation = log_settings::settings().indentation;
        let spaces = "                                  ";
        let indentation = s[..std::cmp::max(indentation, spaces.len())];
        format!("{}{} - {}", indentation, record.level(), record.args())
    };

    let mut builder = LogBuilder::new();
    builder.format(format).filter(None, LogLevelFilter::Info);

    if env::var("RUST_LOG").is_ok() {
       builder.parse(&env::var("RUST_LOG").unwrap());
    }

    builder.init().unwrap();
}

Dependencies

~13KB