basic/basic.rs
1use log::LevelFilter;
2
3fn main() {
4 // The log output is determined by the `NICE_LOG` environment variable as dedicated by the rules
5 // outlined in the repository's readme
6 nice_log::LoggerBuilder::new(LevelFilter::Trace)
7 .build_global()
8 // In this example something would be have gone very wrong if we cannot set up the logger.
9 // If there however is a possibility that the logger is configured multiple times then this
10 // error should be handled appropriately.
11 .expect("A logger has already been set up");
12
13 // When changing some of the level filter above some of these messages may no longer be printed
14 log::error!("This is an error");
15 log::warn!("This is a warning");
16 log::info!("This is a regular log message");
17 log::debug!("This is a debug message, usually only made visible during debug builds");
18 log::trace!("This is a trace message, usually hidden unless explicitly opted into");
19
20 // Debug and trace messages contain the module path
21 some_module::log_from_module();
22}
23
24mod some_module {
25 pub fn log_from_module() {
26 log::debug!("This is a debug message printed from another module");
27 }
28}