log_settings 0.1.2

a tiny crate allowing libraries to change logger settings
Documentation

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();
}