From e9f609cc7d118f6e6d652bfbe000be4085bbd6d2 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Sun, 26 Jun 2022 21:48:27 +0300 Subject: [PATCH] setup log level --- bumblefoot/src/bin/bumblefoot.rs | 10 ++++++---- bumblefoot/src/bin/cmd/default.rs | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/bumblefoot/src/bin/bumblefoot.rs b/bumblefoot/src/bin/bumblefoot.rs index d06fbc0..c7166cb 100644 --- a/bumblefoot/src/bin/bumblefoot.rs +++ b/bumblefoot/src/bin/bumblefoot.rs @@ -7,15 +7,17 @@ pub const BANNER: &str = r#" "#; fn main() { - // just use $ LOG=1 mybin - let env = env_logger::Env::default().filter_or("LOG", "info"); - env_logger::init_from_env(env); - let app = cmd::default::command().subcommand(cmd::validate::command()); let v = app.render_version(); let matches = app.to_owned().get_matches(); + let env = env_logger::Env::default().filter_or( + "LOG", + matches.value_of("log").unwrap_or(log::Level::Info.as_str()), + ); + env_logger::init_from_env(env); + if !matches.is_present("no_banner") { println!( "{}\n {}", diff --git a/bumblefoot/src/bin/cmd/default.rs b/bumblefoot/src/bin/cmd/default.rs index 7baa414..aa5de48 100644 --- a/bumblefoot/src/bin/cmd/default.rs +++ b/bumblefoot/src/bin/cmd/default.rs @@ -32,10 +32,21 @@ pub fn command() -> Command<'static> { .takes_value(false), ) .arg( - Arg::new("verbose") - .long("verbose") - .help("Show details about interactions") - .takes_value(false), + Arg::new("log") + .long("log") + .help("Set logging level") + .value_name("LEVEL") + .possible_values(vec![ + log::LevelFilter::Off.as_str(), + log::LevelFilter::Trace.as_str(), + log::LevelFilter::Debug.as_str(), + log::LevelFilter::Info.as_str(), + log::LevelFilter::Warn.as_str(), + log::LevelFilter::Error.as_str(), + ]) + .default_value(log::Level::Info.as_str()) + .ignore_case(true) + .takes_value(true), ) }