Skip to content

Commit 6cf397e

Browse files
committed
Get a lot more info (nanoseconds, span in/out, thread id) at -vv+ verbosity levels
1 parent 498d603 commit 6cf397e

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

src/main.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
use beavercds_ng::commands;
22
use clap::Parser;
33
use tracing::{trace, Level};
4-
use tracing_subscriber::{fmt::time, EnvFilter};
4+
use tracing_subscriber::{
5+
fmt::{format::FmtSpan, time},
6+
EnvFilter,
7+
};
58

69
mod cli;
710

811
fn main() {
912
let cli = cli::Cli::parse();
1013

11-
// number of 'v' flags influences our crate's log level, all other log levels, and whether or
12-
// not we display the span stack, respectively
13-
let (brcds_level, dep_level, display_spans) = match cli.verbosity {
14-
0 => (Level::INFO, Level::WARN, false),
15-
1 => (Level::DEBUG, Level::INFO, false),
16-
2 => (Level::TRACE, Level::DEBUG, true),
17-
_ => (Level::TRACE, Level::TRACE, true),
14+
// number of 'v' flags influences our crate's log level and all other log levels separately
15+
let (brcds_level, dep_level) = match cli.verbosity {
16+
0 => (Level::INFO, Level::WARN),
17+
1 => (Level::DEBUG, Level::INFO),
18+
2 => (Level::TRACE, Level::DEBUG),
19+
_ => (Level::TRACE, Level::TRACE),
20+
};
21+
// this is our threshold for a lot more (but far from all) information
22+
let (extra_toggles, timestr, events) = if cli.verbosity >= 2 {
23+
(true, "%H:%M:%S%.f", FmtSpan::NEW | FmtSpan::CLOSE)
24+
} else {
25+
(false, "%H:%M:%S", FmtSpan::NONE)
1826
};
1927

2028
// Use RUST_LOG env variable to set log levels if it's set
2129
// Otherwise we use the above levels. Span-stack display always influenced by -v
22-
let timer = time::ChronoLocal::new("%H:%M:%S".to_owned());
2330
tracing_subscriber::fmt()
2431
.with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| {
2532
format!("{}={brcds_level},{dep_level}", env!("CARGO_CRATE_NAME")).into()
2633
}))
27-
.with_timer(timer)
28-
.with_target(display_spans)
34+
.with_timer(time::ChronoLocal::new(timestr.to_string()))
35+
.with_target(extra_toggles)
36+
.with_thread_ids(extra_toggles)
37+
.with_span_events(events)
2938
.init();
3039

3140
trace!("args: {:?}", cli);
32-
3341
// dispatch commands
3442
match &cli.command {
3543
cli::Commands::Validate => commands::validate::run(),

0 commit comments

Comments
 (0)