2023-07-20 01:15:55 -03:00
|
|
|
use crate::cmd_args::{Args, LogFormat};
|
|
|
|
|
use tracing_subscriber;
|
2023-07-27 17:51:23 +02:00
|
|
|
use tracing_subscriber::EnvFilter;
|
2023-07-20 01:15:55 -03:00
|
|
|
|
|
|
|
|
pub fn init(args: &Args) {
|
2023-07-27 17:51:23 +02:00
|
|
|
// Iniitalize a default filter, and then override the builtin default "warning" with our
|
|
|
|
|
// commandline, (default: "info")
|
|
|
|
|
let filter = EnvFilter::from_default_env().add_directive(args.log_level.into());
|
|
|
|
|
|
2023-07-20 01:15:55 -03:00
|
|
|
let trace_sub = tracing_subscriber::fmt()
|
2023-09-20 09:11:16 -07:00
|
|
|
.with_thread_ids(true)
|
2023-07-27 17:51:23 +02:00
|
|
|
.with_env_filter(filter)
|
2023-07-20 01:15:55 -03:00
|
|
|
.with_ansi(!args.no_color);
|
|
|
|
|
|
|
|
|
|
match args.log_format {
|
|
|
|
|
LogFormat::Structured => trace_sub.json().init(),
|
|
|
|
|
LogFormat::Debug => trace_sub.pretty().init(),
|
|
|
|
|
_ => trace_sub.init(),
|
|
|
|
|
};
|
|
|
|
|
}
|