|
1 | 1 | use beavercds_ng::commands;
|
2 | 2 | use clap::Parser;
|
3 | 3 | use tracing::{trace, Level};
|
4 |
| -use tracing_subscriber::{fmt::time, EnvFilter}; |
| 4 | +use tracing_subscriber::{ |
| 5 | + fmt::{format::FmtSpan, time}, |
| 6 | + EnvFilter, |
| 7 | +}; |
5 | 8 |
|
6 | 9 | mod cli;
|
7 | 10 |
|
8 | 11 | fn main() {
|
9 | 12 | let cli = cli::Cli::parse();
|
10 | 13 |
|
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) |
18 | 26 | };
|
19 | 27 |
|
20 | 28 | // Use RUST_LOG env variable to set log levels if it's set
|
21 | 29 | // Otherwise we use the above levels. Span-stack display always influenced by -v
|
22 |
| - let timer = time::ChronoLocal::new("%H:%M:%S".to_owned()); |
23 | 30 | tracing_subscriber::fmt()
|
24 | 31 | .with_env_filter(EnvFilter::try_from_default_env().unwrap_or_else(|_| {
|
25 | 32 | format!("{}={brcds_level},{dep_level}", env!("CARGO_CRATE_NAME")).into()
|
26 | 33 | }))
|
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) |
29 | 38 | .init();
|
30 | 39 |
|
31 | 40 | trace!("args: {:?}", cli);
|
32 |
| - |
33 | 41 | // dispatch commands
|
34 | 42 | match &cli.command {
|
35 | 43 | cli::Commands::Validate => commands::validate::run(),
|
|
0 commit comments