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
use crate::Result;
use hhmmss::Hhmmss;
use log::{Level, LevelFilter, Metadata, Record};
use std::time::Instant;
static LOGGER: Logger = Logger;
struct Logger;
impl log::Log for Logger {
fn enabled(&self, metadata: &Metadata) -> bool {
metadata.level() <= Level::Info
}
fn log(&self, record: &Record) {
let execution_starts_at = Instant::now();
if self.enabled(record.metadata()) {
println!(
"{} {} {}",
execution_starts_at.elapsed().hhmmss(),
record.level(),
record.args()
);
}
}
fn flush(&self) {}
}
pub fn init() -> Result<()> {
let execution_starts_at = Instant::now();
println!("Execution starts at {:?}", execution_starts_at);
log::set_logger(&LOGGER).map(|()| log::set_max_level(LevelFilter::Info))?;
Ok(())
}