1/*! 2Using `env_logger`. 3 4Before running this example, try setting the `MY_LOG_LEVEL` environment variable to `info`: 5 6```no_run,shell 7$ export MY_LOG_LEVEL='info' 8``` 9 10Also try setting the `MY_LOG_STYLE` environment variable to `never` to disable colors 11or `auto` to enable them: 12 13```no_run,shell 14$ export MY_LOG_STYLE=never 15``` 16*/ 17 18#[macro_use] 19extern crate log; 20 21use env_logger::Env; 22 23fn main() { 24 // The `Env` lets us tweak what the environment 25 // variables to read are and what the default 26 // value is if they're missing 27 let env = Env::default() 28 .filter_or("MY_LOG_LEVEL", "trace") 29 .write_style_or("MY_LOG_STYLE", "always"); 30 31 env_logger::init_from_env(env); 32 33 trace!("some trace log"); 34 debug!("some debug log"); 35 info!("some information log"); 36 warn!("some warning log"); 37 error!("some error log"); 38} 39