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