Function env_logger::try_init_from_env [] [src]

pub fn try_init_from_env<'a, E>(env: E) -> Result<(), SetLoggerError> where
    E: Into<Env<'a>>, 

Attempts to initialize the global logger with an env logger from the given environment variables.

This should be called early in the execution of a Rust program. Any log events that occur before initialization will be ignored.

Examples

Initialise a logger using the MY_LOG environment variable for filters and MY_LOG_STYLE for writing colors:

use env_logger::{Builder, Env};

let env = Env::new().filter("MY_LOG").write_style("MY_LOG_STYLE");

env_logger::try_init_from_env(env)?;

Ok(())

Errors

This function will fail if it is called more than once, or if another library has already initialized a global logger.