Created
December 21, 2024 23:14
-
-
Save jfear/c8b1a7ca27b29fc1054017c186faa40e to your computer and use it in GitHub Desktop.
Copied from the clap-verbosity examples folder. This shows how to use the verbosity trait to set tracing log level.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use clap::Parser; | |
use clap_verbosity_flag::Verbosity; | |
/// Foo | |
#[derive(Debug, Parser)] | |
struct Cli { | |
#[command(flatten)] | |
verbosity: Verbosity, | |
} | |
fn main() { | |
let cli = Cli::parse(); | |
tracing_subscriber::fmt() | |
.with_max_level(cli.verbosity) | |
.init(); | |
tracing::error!("Engines exploded"); | |
tracing::warn!("Engines smoking"); | |
tracing::info!("Engines exist"); | |
tracing::debug!("Engine temperature is 200 degrees"); | |
tracing::trace!("Engine subsection is 300 degrees"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also set the default level to Info using: