use log::LevelFilter;
use simple_logger::SimpleLogger;
use time::macros::{format_description, offset};

pub fn init_logger() {
    let log_level: LevelFilter = match std::env::var("LOG_LEVEL") {
        Ok(val) => match val.as_str() {
            "TRACE" => LevelFilter::Trace,
            "DEBUG" => LevelFilter::Debug,
            "INFO" => LevelFilter::Info,
            "WARN" => LevelFilter::Warn,
            "ERROR" => LevelFilter::Error,
            _ => LevelFilter::Info,
        },
        Err(_) => LevelFilter::Info,
    };

    SimpleLogger::new()
        .with_level(log_level)
        .with_timestamp_format(format_description!(
            "[year]-[month]-[day] [hour]:[minute]:[second]"
        ))
        .with_utc_offset(offset!(+2))
        .init()
        .unwrap();
}
