use std::io;
use tracing::info;
use tracing_appender::{non_blocking, rolling};
use tracing_subscriber::{
fmt, prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, EnvFilter, Registry,
};
use crate::config::C_CONFIG;
pub fn init() {
let file_appender = rolling::daily(&C_CONFIG.tracing.dir, &C_CONFIG.tracing.name);
let (non_blocking_appender, _guard) = non_blocking(file_appender);
let env = EnvFilter::try_new(&C_CONFIG.tracing.level).unwrap();
let file_layer = fmt::layer()
.pretty()
.with_ansi(false)
.with_writer(non_blocking_appender);
if C_CONFIG.tracing.console {
let stdout = fmt::layer().pretty().with_writer(io::stdout);
Registry::default()
.with(env)
.with(file_layer)
.with(stdout)
.init();
} else {
Registry::default().with(env).with(file_layer).init();
}
info!("init tracing success.")
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {}
}