-
Notifications
You must be signed in to change notification settings - Fork 287
/
example_utils.rs
43 lines (36 loc) · 1.07 KB
/
example_utils.rs
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
41
42
43
use std::io::Write;
use std::thread;
use chrono::prelude::*;
use env_logger::fmt::Formatter;
use env_logger::Builder;
use log::{LevelFilter, Record};
pub fn setup_logger(log_thread: bool, rust_log: Option<&str>) {
let output_format = move |formatter: &mut Formatter, record: &Record| {
let thread_name = if log_thread {
format!("(t: {}) ", thread::current().name().unwrap_or("unknown"))
} else {
"".to_string()
};
let local_time: DateTime<Local> = Local::now();
let time_str = local_time.format("%H:%M:%S%.3f").to_string();
write!(
formatter,
"{} {}{} - {} - {}\n",
time_str,
thread_name,
record.level(),
record.target(),
record.args()
)
};
let mut builder = Builder::new();
builder
.format(output_format)
.filter(None, LevelFilter::Info);
rust_log.map(|conf| builder.parse_filters(conf));
builder.init();
}
#[allow(dead_code)]
fn main() {
println!("This is not an example");
}