Skip to content

Commit

Permalink
refactor: migrate to built-in tracing support of clap-verbosity-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoniePhiline committed Nov 21, 2024
1 parent 51c06da commit e368050
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ publish = false

[dependencies]
clap = { version = "4.5.4", features = ["derive", "wrap_help"] }
clap-verbosity-flag = "3.0.0"
clap-verbosity-flag = { version = "3.0.0", default-features = false, features = ["tracing"] }
color-eyre = "0.6.3"
crossterm = { version = "0.28.0", features = ["event-stream"] }
futures = "0.3.30"
htmlize = { version = "1.0.5", features = ["unescape"] }
json_dotpath = "1.1.0"
log = "0.4.21"
nix = { version = "0.29.0", features = ["process", "signal"] }
once_cell = "1.19.0"
opentelemetry = "0.23"
Expand Down
26 changes: 2 additions & 24 deletions src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use opentelemetry::KeyValue;
use opentelemetry_sdk::Resource;
use tracing_appender::non_blocking::WorkerGuard;
use tracing_error::ErrorLayer;
use tracing_subscriber::{filter::Directive, layer::SubscriberExt};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::{prelude::*, EnvFilter};

use crate::args::Args;
Expand Down Expand Up @@ -56,28 +56,6 @@ fn env_filter(verbosity: &Verbosity) -> EnvFilter {
// or use `RUST_LOG=target[span{field=value}]=level` for fine-grained verbosity control.
// See https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html
tracing_subscriber::EnvFilter::builder()
.with_default_directive(
LogLevel::from(&verbosity.log_level().unwrap_or(log::Level::Error)).into_directive(),
)
.with_default_directive(verbosity.tracing_level_filter().into())
.from_env_lossy()
}

pub(crate) struct LogLevel(tracing::Level);

impl From<&log::Level> for LogLevel {
fn from(log_level: &log::Level) -> Self {
LogLevel(match log_level {
log::Level::Error => tracing::Level::ERROR,
log::Level::Warn => tracing::Level::WARN,
log::Level::Info => tracing::Level::INFO,
log::Level::Debug => tracing::Level::DEBUG,
log::Level::Trace => tracing::Level::TRACE,
})
}
}

impl LogLevel {
pub(crate) fn into_directive(self) -> Directive {
self.0.into()
}
}

0 comments on commit e368050

Please sign in to comment.