Refactor logging

To supporte more than a single log level `log` and `env_logger` crates
are used. For the application to support the different type of
argument, the verbose argument definition was adapted.
This commit is contained in:
finga 2021-07-07 17:13:08 +02:00
parent 6a41335603
commit 12b117db7e
8 changed files with 107 additions and 36 deletions

View file

@ -21,9 +21,9 @@ enum Command {
global_setting = AppSettings::InferSubcommands,
)]
struct Opts {
/// Produce verbose output
#[clap(short, long, global = true)]
verbose: bool,
/// Produce verbose output, multiple -v options increase the verbosity (max. 3)
#[clap(short, long, global = true, parse(from_occurrences))]
verbose: u32,
#[clap(subcommand)]
command: Command,
}
@ -31,12 +31,22 @@ struct Opts {
fn main() -> Result<()> {
let opts: Opts = Opts::parse();
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or(
match opts.verbose {
0 => "warn",
1 => "info",
2 => "debug",
_ => "trace",
},
))
.init();
match opts.command {
Command::Create(c) => c.run(opts.verbose)?,
Command::Create(c) => c.run()?,
Command::Info(i) => i.run()?,
Command::Unlink(u) => u.run(opts.verbose)?,
Command::Send(s) => s.run(opts.verbose)?,
Command::Recv(r) => r.run(opts.verbose)?,
Command::Unlink(u) => u.run()?,
Command::Send(s) => s.run()?,
Command::Recv(r) => r.run()?,
}
Ok(())