default/
default.rs

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
18use log::{debug, error, info, trace, warn};
19
20use env_logger::Env;
21
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}