land_core/
trace.rs

1use tracing_subscriber::fmt::time::OffsetTime;
2use tracing_subscriber::EnvFilter;
3
4/// init initializes the tracing subscriber.
5/// It supports RUN_LOG env var to set the log level.
6pub fn init() {
7    if std::env::var("RUST_LOG").ok().is_none() {
8        if cfg!(debug_assertions) {
9            std::env::set_var("RUST_LOG", "debug")
10        } else {
11            std::env::set_var("RUST_LOG", "info")
12        }
13    }
14
15    let timer = OffsetTime::new(
16        time::UtcOffset::from_hms(8, 0, 0).unwrap(),
17        time::format_description::parse(
18            "[year]-[month]-[day] [hour]:[minute]:[second].[subsecond digits:3]",
19        )
20        .unwrap(),
21    );
22
23    tracing_subscriber::fmt()
24        .with_timer(timer)
25        .with_env_filter(EnvFilter::from_default_env())
26        .with_target(false)
27        .init();
28}