add verbosity options

This commit is contained in:
Edward Shen 2021-04-20 14:12:20 -04:00
parent db8473d5bf
commit e3f6ff8e71
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 18 additions and 9 deletions

View file

@ -47,10 +47,15 @@ pub struct CliArgs {
/// instead use the filesystem as the buffer backing. This is useful for
/// clients in low (< 1GB) RAM environments.
pub low_memory: bool,
/// Changes verbosity. Default verbosity is INFO, while increasing counts
/// of verbose flags increases to DEBUG and TRACE, respectively.
/// Changes verbosity. Default verbosity is INFO, while increasing counts of
/// verbose flags increases the verbosity to DEBUG and TRACE, respectively.
#[clap(short, long, parse(from_occurrences))]
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
/// you know what you're dealing with.
#[clap(long)]

View file

@ -58,13 +58,17 @@ async fn main() -> Result<(), std::io::Error> {
let cache_path = cli_args.cache_path.clone();
let low_mem_mode = cli_args.low_memory;
match cli_args.verbose {
0 => SimpleLogger::new().with_level(LevelFilter::Info),
1 => SimpleLogger::new().with_level(LevelFilter::Debug),
_ => SimpleLogger::new().with_level(LevelFilter::Trace),
}
.init()
.unwrap();
let log_level = match (cli_args.quiet, cli_args.verbose) {
(n, _) if n > 2 => LevelFilter::Off,
(2, _) => LevelFilter::Error,
(1, _) => LevelFilter::Warn,
(0, 0) => LevelFilter::Info,
(_, 1) => LevelFilter::Debug,
(_, n) if n > 1 => LevelFilter::Trace,
_ => unreachable!(),
};
SimpleLogger::new().with_level(log_level).init().unwrap();
print_preamble_and_warnings();