• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*!
2 Disabling parts of the default format.
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 If you want to control the logging output completely, see the `custom_logger` example.
18 */
19 
20 #[macro_use]
21 extern crate log;
22 
23 use env_logger::{Builder, Env};
24 
init_logger()25 fn init_logger() {
26     let env = Env::default()
27         .filter("MY_LOG_LEVEL")
28         .write_style("MY_LOG_STYLE");
29 
30     Builder::from_env(env)
31         .format_level(false)
32         .format_timestamp_nanos()
33         .init();
34 }
35 
main()36 fn main() {
37     init_logger();
38 
39     info!("a log from `MyLogger`");
40 }
41