forked from feather-rs/feather
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogging.rs
More file actions
33 lines (32 loc) · 1.17 KB
/
logging.rs
File metadata and controls
33 lines (32 loc) · 1.17 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
use colored::Colorize;
use log::{Level, LevelFilter};
pub fn init(level: LevelFilter) {
fern::Dispatch::new()
.format(|out, message, record| {
let level_string = match record.level() {
Level::Error => record.level().to_string().red(),
Level::Warn => record.level().to_string().yellow(),
Level::Info => record.level().to_string().cyan(),
Level::Debug => record.level().to_string().purple(),
Level::Trace => record.level().to_string().normal(),
};
let target = if !record.target().is_empty() {
record.target()
} else {
record.module_path().unwrap_or_default()
};
out.finish(format_args!(
"{} {:<5} [{}] {}",
chrono::Local::now().format("%Y-%m-%d %H:%M:%S,%3f"),
level_string,
target,
message,
));
})
.level(level)
// cranelift_codegen spams debug-level logs
.level_for("cranelift_codegen", LevelFilter::Info)
.chain(std::io::stdout())
.apply()
.unwrap();
}