From 53334533eb6399dc4b931fa3f61c32b5e28bd9e7 Mon Sep 17 00:00:00 2001 From: orhun Date: Wed, 16 Jun 2021 02:04:14 +0300 Subject: [PATCH] refactor(logs): improve logging --- git-cliff/src/args.rs | 6 +++--- git-cliff/src/changelog.rs | 19 +++++++++---------- git-cliff/src/lib.rs | 2 +- git-cliff/src/main.rs | 4 +++- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/git-cliff/src/args.rs b/git-cliff/src/args.rs index de2ec79520..9c564b0b2e 100644 --- a/git-cliff/src/args.rs +++ b/git-cliff/src/args.rs @@ -17,9 +17,9 @@ use structopt::StructOpt; rename_all_env = "screaming-snake" )] pub struct Opt { - /// Activates the debug mode - #[structopt(short, long)] - pub debug: bool, + /// Activates the verbose mode + #[structopt(short, long, parse(from_occurrences), alias = "debug")] + pub verbose: u8, /// Sets the configuration file. #[structopt( short, diff --git a/git-cliff/src/changelog.rs b/git-cliff/src/changelog.rs index ebcbb3ae6f..e3a2c81186 100644 --- a/git-cliff/src/changelog.rs +++ b/git-cliff/src/changelog.rs @@ -39,6 +39,7 @@ impl<'a> Changelog<'a> { /// Processes the commits and omits the ones that doesn't match the /// criteria set by configuration file. fn process_commits(&mut self) { + debug!("Processing the commits..."); let config = &self.config; self.releases.iter_mut().for_each(|release| { release.commits = release @@ -52,7 +53,7 @@ impl<'a> Changelog<'a> { ) { Ok(commit) => Some(commit), Err(e) => { - debug!("Cannot process commit: {} ({})", commit.id, e); + trace!("{} ({})", commit.id[..7].to_string(), e); None } } @@ -63,6 +64,7 @@ impl<'a> Changelog<'a> { /// Processes the releases and filters them out based on the configuration. fn process_releases(&mut self) { + debug!("Processing the releases..."); let skip_regex = self.config.git.skip_tags.as_ref(); self.releases = self .releases @@ -71,21 +73,16 @@ impl<'a> Changelog<'a> { .rev() .filter(|release| { if release.commits.is_empty() { - debug!( - "Release {} doesn't have any commits", - release - .version - .as_ref() - .cloned() - .unwrap_or_else(|| String::from("[?]")) - ); + if let Some(version) = release.version.as_ref().cloned() { + trace!("Release doesn't have any commits: {}", version); + } false } else if let Some(version) = &release.version { !skip_regex .map(|r| { let skip_tag = r.is_match(version); if skip_tag { - debug!("Skipping release: {}", version) + trace!("Skipping release: {}", version) } skip_tag }) @@ -99,6 +96,7 @@ impl<'a> Changelog<'a> { /// Generates the changelog and writes it to the given output. pub fn generate(&self, out: &mut W) -> Result<()> { + debug!("Generating changelog..."); if let Some(header) = &self.config.changelog.header { write!(out, "{}", header)?; } @@ -117,6 +115,7 @@ impl<'a> Changelog<'a> { mut changelog: String, out: &mut W, ) -> Result<()> { + debug!("Generating changelog and prepending..."); if let Some(header) = &self.config.changelog.header { changelog = changelog.replacen(header, "", 1); } diff --git a/git-cliff/src/lib.rs b/git-cliff/src/lib.rs index e6d4ad7b79..725dd4fe8b 100644 --- a/git-cliff/src/lib.rs +++ b/git-cliff/src/lib.rs @@ -97,7 +97,7 @@ pub fn run(mut args: Opt) -> Result<()> { if let Some(commit_id) = commits.first().map(|c| c.id().to_string()) { match tags.get(&commit_id) { Some(tag) => { - debug!("There is already a tag ({}) for {}", tag, commit_id) + warn!("There is already a tag ({}) for {}", tag, commit_id) } None => { tags.insert(commit_id, tag); diff --git a/git-cliff/src/main.rs b/git-cliff/src/main.rs index 70c8d73447..410dd5cdda 100644 --- a/git-cliff/src/main.rs +++ b/git-cliff/src/main.rs @@ -5,8 +5,10 @@ use structopt::StructOpt; fn main() { let args = Opt::from_args(); - if args.debug { + if args.verbose == 1 { env::set_var("RUST_LOG", "debug"); + } else if args.verbose > 1 { + env::set_var("RUST_LOG", "trace"); } else if env::var_os("RUST_LOG").is_none() { env::set_var("RUST_LOG", "info"); }