From 46eedec11e805ac26177a6e2fe5f68f84778aa00 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Wed, 4 Feb 2026 11:49:56 -0800 Subject: [PATCH] fixup log level handling --- src/main.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2035e8b..0c46d06 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,12 +28,29 @@ enum Level { Error, } +impl From for tracing::Level { + fn from(level: Level) -> Self { + match level { + Level::Debug => tracing::Level::DEBUG, + Level::Info => tracing::Level::INFO, + Level::Warn => tracing::Level::WARN, + Level::Error => tracing::Level::ERROR, + } + } +} + +impl Level { + fn level(self) -> tracing::Level { + self.into() + } +} + #[derive(Parser)] struct Args { /// TOML configuration to load #[arg(short, long, default_value_t = String::from("config.toml"))] config_file: String, - #[arg(value_enum, default_value_t = Level::Warn)] + #[arg(value_enum, default_value_t = Level::Info)] log_level: Level, } @@ -102,14 +119,16 @@ async fn dummy_consumer(mut chan: ChimemonTargetChannel, cancel: CancellationTok #[tokio::main(flavor = "current_thread")] async fn main() -> Result<(), Box> { + let args = Args::parse(); tracing_subscriber::fmt() - .with_env_filter(EnvFilter::try_from_default_env().unwrap_or(EnvFilter::default())) + .with_env_filter( + EnvFilter::try_from_default_env() + .unwrap_or(EnvFilter::default().add_directive(args.log_level.level().into())), + ) // .event_format(format::Format::default().pretty()) .with_span_events(FmtSpan::CLOSE) .init(); - let args = Args::parse(); - info!("{PROGRAM_NAME} v{VERSION} starting..."); let fig = Figment::new() .merge(Config::default())