Crate pretty_flexible_env_logger

Crate pretty_flexible_env_logger 

Source
Expand description

A logger configured via run-time value or one taken from an environment variable which writes to standard error with nice colored output for log levels.

§Example

use log::{debug,info,warn,error};
use std::env;

fn main() {
    let args: Vec<String> = env::args().collect();
    let default = "RUST_LOG".to_string();
    let level = args.get(1).unwrap_or(&default);
    if let Err(e) = pretty_flexible_env_logger::try_init_with(level) {
        eprintln!("Some custom msg {}", e);
        panic!("error!") // or whatever
    }
     
    info!("info");
    warn!("warn");
    error!("error");
    debug!("debug");
}

§Defaults

The defaults can be setup by calling init() or try_init() at the start of the program.

§Enable logging

This crate uses pretty_env_logger internally, so the same ways of enabling logs through an environment variable are supported.

Functions§

init
Initializes default global logger.
init_timed
Initializes default global logger with timed entries.
init_timed_with
Initializes the timed global logger with a custom configuration.
init_with
Initializes the global logger with a custom configuration.
try_init
Tries to initialize default global logger.
try_init_custom_string
Tries to initialize the global logger with custom filtering directives.
try_init_timed
Tries to initialize default global logger with timed entries.
try_init_timed_custom_string
Tries to initialize the timed global logger with custom filtering directives.
try_init_timed_with
Tries to initialize the timed global logger with a custom configuration.
try_init_with
Tries to initialize the global logger with a custom configuration.