Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a TRACE log level enabled by two --verbose flags #113

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Display the total cleaned amount when sweeping multiple projects [#45](https://github.com/holmgr/cargo-sweep/pull/45)
- No longer give a hard error when a custom toolchain gives an error [#67](https://github.com/holmgr/cargo-sweep/pull/67)
- Don't print colors when stdout is not a terminal [#69](https://github.com/holmgr/cargo-sweep/pull/69)
- Add long `--verbose` and `--recursive` flags [#73](https://github.com/holmgr/cargo-sweep/pull/73)
Expand All @@ -17,13 +18,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactor and add `-m` as a short flag for `--maxsize` [#87](https://github.com/holmgr/cargo-sweep/pull/87)
- Only show toolchain list once when using `--installed` [#88](https://github.com/holmgr/cargo-sweep/pull/88)
- Support multiple projects as input via CLI [#101](https://github.com/holmgr/cargo-sweep/pull/101)
- Add a `TRACE` log level enabled by two `--verbose` flags [#113](https://github.com/holmgr/cargo-sweep/pull/113)

### Fixed

- When rustc fails, show stderr if stdout is empty [#63](https://github.com/holmgr/cargo-sweep/pull/63)
- Kibibytes are now printed as `KiB`, not `kiB` [#69](https://github.com/holmgr/cargo-sweep/pull/69)
- Exit with non-zero status on failure [#72](https://github.com/holmgr/cargo-sweep/pull/72)
- Keep stamp file on dry run [#100](https://github.com/holmgr/cargo-sweep/pull/100)
- Fix invisible output in white-themed terminals [#103](https://github.com/holmgr/cargo-sweep/pull/103)

## **0.6.2** and prior

Expand Down
6 changes: 3 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ pub struct Args {
#[arg(long, value_delimiter = ',')]
toolchains: Vec<String>,

/// Turn verbose information on
#[arg(short, long)]
pub verbose: bool,
/// Enable DEBUG logs (use twice for TRACE logs)
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
}

impl Args {
Expand Down
5 changes: 3 additions & 2 deletions src/fingerprint.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(deprecated)]
use anyhow::{bail, Context, Error};
use log::trace;
use log::{debug, info, warn};
use serde_derive::Deserialize;
use serde_json::from_str;
Expand Down Expand Up @@ -94,7 +95,7 @@ fn load_all_fingerprints_built_with(
}
}
}
debug!("Hashs to keep: {:#?}", keep);
trace!("Hashs to keep: {:#?}", keep);
Comment on lines -97 to +98
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --verbose output used to be unreadable due to the pollution of the hashes listing.

Now these hashes are behind the TRACE level, and it can be enabled with -v -v or -vv (--verbose twice).

Ok(keep)
}

Expand Down Expand Up @@ -156,7 +157,7 @@ fn load_all_fingerprints_newer_than(
}
}
}
debug!("Hashs to keep: {:#?}", keep);
trace!("Hashs to keep: {:#?}", keep);
Ok(keep)
}

Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ use self::stamp::Timestamp;
use self::util::format_bytes;

/// Setup logging according to verbose flag.
fn setup_logging(verbose: bool) {
let level = if verbose {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
fn setup_logging(verbosity_level: u8) {
let level = match verbosity_level {
0 => log::LevelFilter::Info,
1 => log::LevelFilter::Debug,
2.. => log::LevelFilter::Trace,
};

let isatty = std::io::stdout().is_tty();
Expand Down
2 changes: 1 addition & 1 deletion tests/usage.trycmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Options:
-s, --stamp Store timestamp file at the given path, is used by file option
-t, --time <DAYS> Number of days backwards to keep
--toolchains <TOOLCHAINS> Toolchains currently installed by rustup that should have their artifacts kept
-v, --verbose Turn verbose information on
-v, --verbose... Enable DEBUG logs (use twice for TRACE logs)
-h, --help Print help (see more with '--help')
-V, --version Print version

Expand Down
Loading