Available on crate feature
serde only.Expand description
Control log level with a --verbose flag for your CLI
This crate adds a --verbose flag to your CLI. Most of its code
came from clap_verbosity_flag and
as such, it is largely a superset and a drop-in replacement of that crate.
§Examples
To get --quiet and --verbose flags through your entire program, just flatten
Verbosity:
#[command(flatten)]
verbose: Verbosity,You can then use this to configure your logger:
let cli = Cli::parse();
env_logger::Builder::new()
.filter_level(cli.verbose.log_level_filter())
.init();By default, this will only report errors.
-qsilences output-vshow warnings-vvshow info-vvvshow debug-vvvvshow trace
You can also customize the default logging level:
use clap_verbosity::{Verbosity, InfoLevel};
/// The CLI
#[derive(Debug, Parser)]
struct Cli {
#[command(flatten)]
verbose: Verbosity<InfoLevel>,
}Or implement LogLevel yourself for more control.
Modules§
Structs§
Enums§
- Level
- An enum representing the available verbosity levels of the logger.
- Level
Filter - An enum representing the available verbosity level filters of the logger.
Traits§
Functions§
- level_
enum - Converts an i8 to an Optionlog::Level.
- level_
value - Converts an Optionlog::Level to an i8.