eva_common/
console_logger.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use once_cell::sync::Lazy;

static CONSOLE_LOG_NO_TIMESTAMP: Lazy<bool> =
    Lazy::new(|| std::env::var("EVA_CONSOLE_LOG_NO_TIMESTAMP").map_or(false, |v| v == "1"));

#[inline]
pub fn console_log_with_timestamp() -> bool {
    !*CONSOLE_LOG_NO_TIMESTAMP
}

pub fn configure_env_logger(verbose: bool) {
    let mut builder = env_logger::Builder::new();
    builder.target(env_logger::Target::Stdout);
    builder.filter_level(if verbose {
        log::LevelFilter::Trace
    } else {
        log::LevelFilter::Info
    });
    if !console_log_with_timestamp() {
        builder.format_timestamp(None);
    }
    builder.init();
}