From b4acb55d0ce6fe8bde383a33b3d19ce2648aca57 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Wed, 2 Aug 2023 00:13:34 +0200 Subject: [PATCH] feat: hack get in control of log level I haven't found a good way of enabling all of mine, but disabling all of theirs. as such right now it is a deny list, where some entries reqwest,cliff,hyper is set to error, and our own is controlled via. Signed-off-by: kjuulh --- Cargo.toml | 2 +- crates/cuddle-please-commands/src/command.rs | 18 ++++++++++++++++++ crates/cuddle-please-misc/src/args.rs | 17 +++++++++++++++++ crates/cuddle-please-misc/src/lib.rs | 2 +- crates/cuddle-please/src/main.rs | 1 - 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1e60b02..2eedcfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ cuddle-please-misc = { path = "crates/cuddle-please-misc" } anyhow = { version = "1.0.72" } tracing = { version = "0.1", features = ["log"] } -tracing-subscriber = { version = "0.3.17" } +tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } clap = { version = "4.3.19", features = ["derive", "env"] } dotenv = { version = "0.15.0" } url = { version = "2.4.0" } diff --git a/crates/cuddle-please-commands/src/command.rs b/crates/cuddle-please-commands/src/command.rs index 3265116..303d708 100644 --- a/crates/cuddle-please-commands/src/command.rs +++ b/crates/cuddle-please-commands/src/command.rs @@ -11,6 +11,8 @@ use cuddle_please_misc::{ ConsoleUi, DynRemoteGitClient, DynUi, GiteaClient, GlobalArgs, LocalGitClient, StdinFn, VcsClient, }; +use tracing::Level; +use tracing_subscriber::{prelude::__tracing_subscriber_SubscriberExt, EnvFilter}; use crate::{ config_command::{ConfigCommand, ConfigCommandHandler}, @@ -92,6 +94,22 @@ impl Command { let git_client = self.get_git(&config)?; let gitea_client = self.get_gitea_client(&config); + let filter = match self.global.log_level { + cuddle_please_misc::LogLevel::None => None, + cuddle_please_misc::LogLevel::Trace => Some(Level::TRACE), + cuddle_please_misc::LogLevel::Debug => Some(Level::DEBUG), + cuddle_please_misc::LogLevel::Info => Some(Level::INFO), + cuddle_please_misc::LogLevel::Error => Some(Level::ERROR), + }; + + if let Some(filter) = filter { + let env_filter = EnvFilter::builder().with_regex(false).parse(format!( + "{},hyper=error,reqwest=error,git_cliff_core=error", + filter + ))?; + tracing_subscriber::fmt().with_env_filter(env_filter).init(); + } + match &self.commands { Some(Commands::Release {}) => { ReleaseCommandHandler::new(self.ui, config, git_client, gitea_client) diff --git a/crates/cuddle-please-misc/src/args.rs b/crates/cuddle-please-misc/src/args.rs index b57c205..87265e8 100644 --- a/crates/cuddle-please-misc/src/args.rs +++ b/crates/cuddle-please-misc/src/args.rs @@ -52,6 +52,15 @@ config-stdin will consume stdin until the channel is closed via. EOF" default_value = "gitea" )] pub engine: RemoteEngine, + + #[arg( + env = "CUDDLE_PLEASE_LOG_LEVEL", + long, + global = true, + help_heading = "Global", + default_value = "none" + )] + pub log_level: LogLevel, } #[derive(ValueEnum, Clone, Debug)] @@ -59,3 +68,11 @@ pub enum RemoteEngine { Local, Gitea, } +#[derive(ValueEnum, Clone, Debug)] +pub enum LogLevel { + None, + Trace, + Debug, + Info, + Error, +} diff --git a/crates/cuddle-please-misc/src/lib.rs b/crates/cuddle-please-misc/src/lib.rs index e7f35be..91869cc 100644 --- a/crates/cuddle-please-misc/src/lib.rs +++ b/crates/cuddle-please-misc/src/lib.rs @@ -6,7 +6,7 @@ mod local_git_client; mod ui; mod versioning; -pub use args::{GlobalArgs, RemoteEngine, StdinFn}; +pub use args::{GlobalArgs, LogLevel, RemoteEngine, StdinFn}; pub use cliff::{changelog_parser, ChangeLogBuilder}; pub use git_client::VcsClient; pub use gitea_client::{Commit, DynRemoteGitClient, GiteaClient, RemoteGitEngine, Tag}; diff --git a/crates/cuddle-please/src/main.rs b/crates/cuddle-please/src/main.rs index 5f3e099..8e41a8f 100644 --- a/crates/cuddle-please/src/main.rs +++ b/crates/cuddle-please/src/main.rs @@ -2,7 +2,6 @@ use cuddle_please_commands::PleaseCommand; fn main() -> anyhow::Result<()> { dotenv::dotenv().ok(); - tracing_subscriber::fmt::init(); let current_dir = std::env::current_dir().ok(); let current_dir = current_dir.as_deref();