forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.rs
More file actions
40 lines (37 loc) · 1.16 KB
/
logging.rs
File metadata and controls
40 lines (37 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use log::info;
use crate::Configuration;
pub fn setup_logging(cfg: &Configuration) {
let log_level = match &cfg.log_level {
None => log::LevelFilter::Info,
Some(level) => {
match level.as_str() {
"off" => log::LevelFilter::Off,
"trace" => log::LevelFilter::Trace,
"debug" => log::LevelFilter::Debug,
"info" => log::LevelFilter::Info,
"warn" => log::LevelFilter::Warn,
"error" => log::LevelFilter::Error,
_ => {
panic!("Unknown log level encountered: '{}'", level.as_str());
}
}
}
};
if let Err(_err) = fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
"{} [{}][{}] {}",
chrono::Local::now().format("%+"),
record.target(),
record.level(),
message
))
})
.level(log_level)
.chain(std::io::stdout())
.apply()
{
panic!("Failed to initialize logging.")
}
info!("logging initialized.");
}