Skip to content

Commit 6707cdd

Browse files
committed
Better tracing granularity for but-testing
1 parent 31243e9 commit 6707cdd

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

crates/but-testing/src/args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::path::PathBuf;
66
#[clap(name = "gitbutler-cli", about = "A CLI for GitButler", version = option_env!("GIX_VERSION"))]
77
pub struct Args {
88
/// Enable tracing for debug and performance information printed to stderr.
9-
#[clap(short = 'd', long)]
10-
pub trace: bool,
9+
#[clap(short = 'd', long, action = clap::ArgAction::Count,)]
10+
pub trace: u8,
1111
/// Run as if gitbutler-cli was started in PATH instead of the current working directory.
1212
#[clap(short = 'C', long, default_value = ".", value_name = "PATH")]
1313
pub current_dir: PathBuf,

crates/but-testing/src/main.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ mod command;
1818
async fn main() -> Result<()> {
1919
let args: Args = clap::Parser::parse();
2020

21-
if args.trace {
22-
trace::init()?;
21+
if args.trace > 0 {
22+
trace::init(args.trace)?;
2323
}
2424
let _op_span = tracing::info_span!("cli-op").entered();
2525
static CHANNEL: Option<&str> = option_env!("CHANNEL");
@@ -224,13 +224,17 @@ mod trace {
224224
use tracing_subscriber::layer::SubscriberExt;
225225
use tracing_subscriber::util::SubscriberInitExt;
226226

227-
pub fn init() -> anyhow::Result<()> {
227+
pub fn init(level: u8) -> anyhow::Result<()> {
228228
tracing_subscriber::registry()
229229
.with(
230230
tracing_forest::ForestLayer::from(
231231
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr),
232232
)
233-
.with_filter(LevelFilter::DEBUG),
233+
.with_filter(match level {
234+
1 => LevelFilter::INFO,
235+
2 => LevelFilter::DEBUG,
236+
_ => LevelFilter::TRACE,
237+
}),
234238
)
235239
.init();
236240
Ok(())

0 commit comments

Comments
 (0)