#settings #log #struct #change #tiny #allowing

yanked log_settings

a tiny crate allowing libraries to change logger settings

3 releases

Uses old Rust 2015

0.1.2 May 8, 2018
0.1.1 May 31, 2016
0.1.0 May 31, 2016

#48 in #allowing


Used in seer

MIT license

4KB

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

~10KB