diff --git a/Cargo.lock b/Cargo.lock index fe80d43..2b8f45e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -239,12 +239,12 @@ dependencies = [ [[package]] name = "clap-verbosity-flag" -version = "2.2.3" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34c77f67047557f62582784fd7482884697731b2932c7d37ced54bce2312e1e2" +checksum = "42dcf89bb9d98abb02e9a4a8ef1cce429e547a803460a8245c399860985d5281" dependencies = [ "clap", - "log", + "tracing-core", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 3e60cac..d977c4e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,16 +14,13 @@ axum-auth = { version = "0.7", default-features = false, features = [ axum-client-ip = "0.6" base64 = "0.22" clap = { version = "4", features = ["derive", "env"] } -clap-verbosity-flag = "2" +clap-verbosity-flag = { version = "3", default-features = false, features = [ + "tracing", +] } http = "1" miette = { version = "7", features = ["fancy"] } ring = { version = "0.17", features = ["std"] } -tokio = { version = "1", features = [ - "macros", - "rt", - "process", - "io-util", -] } +tokio = { version = "1", features = ["macros", "rt", "process", "io-util"] } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } diff --git a/src/main.rs b/src/main.rs index 7e2ffae..e216b58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use clap_verbosity_flag::Verbosity; use http::StatusCode; use miette::{bail, ensure, Context, IntoDiagnostic, Result}; use tokio::io::AsyncWriteExt; -use tracing::{debug, error, info, level_filters::LevelFilter, trace, warn}; +use tracing::{debug, error, info, trace, warn}; use tracing_subscriber::EnvFilter; mod password; @@ -28,7 +28,7 @@ const DEFAULT_SALT: &str = "UpdateMyDNS"; #[derive(Debug, Parser)] struct Opts { #[command(flatten)] - verbosity: Verbosity, + verbosity: Verbosity, /// Ip address of the server #[arg(long, default_value = "127.0.0.1")] @@ -151,28 +151,13 @@ fn main() -> Result<()> { // parse cli arguments let mut args = Opts::parse(); - debug!("{args:?}"); // configure logger let subscriber = tracing_subscriber::FmtSubscriber::builder() .without_time() .with_env_filter( EnvFilter::builder() - .with_default_directive( - if args.verbosity.is_present() { - match args.verbosity.log_level_filter() { - clap_verbosity_flag::LevelFilter::Off => LevelFilter::OFF, - clap_verbosity_flag::LevelFilter::Error => LevelFilter::ERROR, - clap_verbosity_flag::LevelFilter::Warn => LevelFilter::WARN, - clap_verbosity_flag::LevelFilter::Info => LevelFilter::INFO, - clap_verbosity_flag::LevelFilter::Debug => LevelFilter::DEBUG, - clap_verbosity_flag::LevelFilter::Trace => LevelFilter::TRACE, - } - } else { - LevelFilter::WARN - } - .into(), - ) + .with_default_directive(args.verbosity.tracing_level_filter().into()) .from_env_lossy(), ) .finish(); @@ -180,6 +165,8 @@ fn main() -> Result<()> { .into_diagnostic() .wrap_err("setting global tracing subscriber")?; + debug!("{args:?}"); + // process subcommand if let Some(cmd) = args.subcommand.take() { return cmd.process(&args);