add verbosity options
This commit is contained in:
parent
db8473d5bf
commit
e3f6ff8e71
2 changed files with 18 additions and 9 deletions
|
@ -47,10 +47,15 @@ pub struct CliArgs {
|
||||||
/// instead use the filesystem as the buffer backing. This is useful for
|
/// instead use the filesystem as the buffer backing. This is useful for
|
||||||
/// clients in low (< 1GB) RAM environments.
|
/// clients in low (< 1GB) RAM environments.
|
||||||
pub low_memory: bool,
|
pub low_memory: bool,
|
||||||
/// Changes verbosity. Default verbosity is INFO, while increasing counts
|
/// Changes verbosity. Default verbosity is INFO, while increasing counts of
|
||||||
/// of verbose flags increases to DEBUG and TRACE, respectively.
|
/// verbose flags increases the verbosity to DEBUG and TRACE, respectively.
|
||||||
#[clap(short, long, parse(from_occurrences))]
|
#[clap(short, long, parse(from_occurrences))]
|
||||||
pub verbose: usize,
|
pub verbose: usize,
|
||||||
|
/// Changes verbosity. Default verbosity is INFO, while increasing counts of
|
||||||
|
/// quiet flags decreases the verbosity to WARN, ERROR, and no logs,
|
||||||
|
/// respectively.
|
||||||
|
#[clap(short, long, parse(from_occurrences), conflicts_with = "verbose")]
|
||||||
|
pub quiet: usize,
|
||||||
/// Overrides the upstream URL to fetch images from. Don't use this unless
|
/// Overrides the upstream URL to fetch images from. Don't use this unless
|
||||||
/// you know what you're dealing with.
|
/// you know what you're dealing with.
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -58,13 +58,17 @@ async fn main() -> Result<(), std::io::Error> {
|
||||||
let cache_path = cli_args.cache_path.clone();
|
let cache_path = cli_args.cache_path.clone();
|
||||||
let low_mem_mode = cli_args.low_memory;
|
let low_mem_mode = cli_args.low_memory;
|
||||||
|
|
||||||
match cli_args.verbose {
|
let log_level = match (cli_args.quiet, cli_args.verbose) {
|
||||||
0 => SimpleLogger::new().with_level(LevelFilter::Info),
|
(n, _) if n > 2 => LevelFilter::Off,
|
||||||
1 => SimpleLogger::new().with_level(LevelFilter::Debug),
|
(2, _) => LevelFilter::Error,
|
||||||
_ => SimpleLogger::new().with_level(LevelFilter::Trace),
|
(1, _) => LevelFilter::Warn,
|
||||||
}
|
(0, 0) => LevelFilter::Info,
|
||||||
.init()
|
(_, 1) => LevelFilter::Debug,
|
||||||
.unwrap();
|
(_, n) if n > 1 => LevelFilter::Trace,
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
SimpleLogger::new().with_level(log_level).init().unwrap();
|
||||||
|
|
||||||
print_preamble_and_warnings();
|
print_preamble_and_warnings();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue