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

Fix log verbosity calculation #1255

Merged
merged 1 commit into from
Apr 11, 2024
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
15 changes: 1 addition & 14 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "c06
camino = { version = "1", features = ["serde1"] }
cargo_metadata = ">=0.18"
clap = { version = "4", features = ["derive", "env", "string"] }
clap-verbosity-flag = "2"
console = "0.15"
darling = "0.20"
data-encoding = "2"
Expand Down
1 change: 0 additions & 1 deletion plugins/cairo-lang-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ repository.workspace = true
cairo-lang-macro-attributes = { path = "../cairo-lang-macro-attributes" }
cairo-lang-macro-stable = { path = "../cairo-lang-macro-stable" }
linkme.workspace = true
scarb-stable-hash = { path = "../../utils/scarb-stable-hash" }

[dev-dependencies]
serde.workspace = true
Expand Down
3 changes: 0 additions & 3 deletions scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ cairo-lang-syntax.workspace = true
cairo-lang-test-plugin.workspace = true
cairo-lang-utils.workspace = true
camino.workspace = true
clap-verbosity-flag.workspace = true
clap.workspace = true
create-output-dir = { path = "../utils/create-output-dir" }
data-encoding.workspace = true
Expand Down Expand Up @@ -72,15 +71,13 @@ thiserror.workspace = true
tokio.workspace = true
toml.workspace = true
toml_edit.workspace = true
tracing-log.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
typed-builder.workspace = true
url.workspace = true
walkdir.workspace = true
which.workspace = true
windows-sys.workspace = true
zip.workspace = true
zstd.workspace = true

[target.'cfg(not(target_os = "linux"))'.dependencies]
Expand Down
3 changes: 3 additions & 0 deletions utils/scarb-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ scarb-metadata = { version = "1", path = "../../scarb-metadata" }
serde.workspace = true
serde_json.workspace = true
tracing-core.workspace = true

[dev-dependencies]
test-case.workspace = true
58 changes: 51 additions & 7 deletions utils/scarb-ui/src/args/verbosity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ pub struct VerbositySpec {
impl Verbosity {
fn level_value(level: Self) -> i8 {
match level {
Self::Quiet => 0,
Self::Normal => 2,
Self::Verbose => 4,
Self::Quiet => -1,
Self::Normal => 0,
Self::Verbose => 1,
}
}
}
Expand All @@ -62,8 +62,7 @@ impl VerbositySpec {
}

fn integer_verbosity(&self) -> i8 {
let int_level = Verbosity::level_value(Verbosity::default()) - (self.quiet as i8)
+ (self.verbose as i8);
let int_level = (self.verbose as i8) - (self.quiet as i8);
if self.is_present() {
int_level
} else {
Expand All @@ -77,9 +76,54 @@ impl VerbositySpec {
impl From<VerbositySpec> for Verbosity {
fn from(spec: VerbositySpec) -> Self {
match spec.integer_verbosity() {
v if v < 2 => Verbosity::Quiet,
2 => Verbosity::Normal,
v if v < 0 => Verbosity::Quiet,
0 => Verbosity::Normal,
_ => Verbosity::Verbose,
}
}
}

#[cfg(test)]
mod tests {
use test_case::test_case;

use crate::args::VerbositySpec;
use crate::Verbosity;

#[test_case(Verbosity::Quiet)]
#[test_case(Verbosity::Normal)]
#[test_case(Verbosity::Verbose)]
fn verbosity_serialization_identity(level: Verbosity) {
assert_eq!(
Verbosity::from(VerbositySpec {
verbose: 0,
quiet: 0,
verbosity: Some(level),
}),
level
);
}

#[test_case(2, 0, Verbosity::Quiet, tracing_core::LevelFilter::OFF)]
#[test_case(1, 0, Verbosity::Quiet, tracing_core::LevelFilter::OFF)]
#[test_case(0, 0, Verbosity::Normal, tracing_core::LevelFilter::ERROR)]
#[test_case(0, 1, Verbosity::Verbose, tracing_core::LevelFilter::WARN)]
#[test_case(0, 2, Verbosity::Verbose, tracing_core::LevelFilter::INFO)]
#[test_case(0, 3, Verbosity::Verbose, tracing_core::LevelFilter::DEBUG)]
#[test_case(0, 4, Verbosity::Verbose, tracing_core::LevelFilter::TRACE)]
#[test_case(0, 5, Verbosity::Verbose, tracing_core::LevelFilter::TRACE)]
fn verbosity_levels(
quiet: u8,
verbose: u8,
level: Verbosity,
trace: tracing_core::LevelFilter,
) {
let spec = VerbositySpec {
verbose,
quiet,
verbosity: None,
};
assert_eq!(spec.as_trace(), trace);
assert_eq!(Verbosity::from(spec), level);
}
}
1 change: 0 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ publish = false
anyhow.workspace = true
clap.workspace = true
semver.workspace = true
serde.workspace = true
serde_json.workspace = true
time.workspace = true
toml_edit.workspace = true
Expand Down
Loading