aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-17 03:42:38 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-17 03:42:38 -0400
commit64342b8acd0ef3accfafc90c7ebf17bf98fd38e6 (patch)
tree0b171267cac91d9dc70c89833579c8365c52a06e
parente2df352ce6dbdbe8ac8076837c8f5d2cbd69208f (diff)
downloadteleterm-64342b8acd0ef3accfafc90c7ebf17bf98fd38e6.tar.gz
teleterm-64342b8acd0ef3accfafc90c7ebf17bf98fd38e6.zip
hide all logs except error logs for interactive subcommands
this should let us use the logger more idiomatically without interfering with normal command output
-rw-r--r--Cargo.toml2
-rw-r--r--src/cmd.rs17
-rw-r--r--src/main.rs4
3 files changed, 16 insertions, 7 deletions
diff --git a/Cargo.toml b/Cargo.toml
index be024d7..3322413 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@ directories = "2"
env_logger = "0.7"
futures = "0.1"
lazy_static = "1"
-log = "0.4"
+log = { version = "0.4", features = ["release_max_level_info"] }
mio = "0.6"
native-tls = "0.2"
oauth2 = "3.0.0-alpha.3" # need the alpha for async support
diff --git a/src/cmd.rs b/src/cmd.rs
index 6566e18..8d305d2 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -10,6 +10,7 @@ struct Command {
name: &'static str,
cmd: &'static dyn for<'a, 'b> Fn(clap::App<'a, 'b>) -> clap::App<'a, 'b>,
run: &'static dyn for<'a> Fn(&clap::ArgMatches<'a>) -> Result<()>,
+ log_level: &'static str,
}
const COMMANDS: &[Command] = &[
@@ -17,26 +18,31 @@ const COMMANDS: &[Command] = &[
name: "stream",
cmd: &stream::cmd,
run: &stream::run,
+ log_level: "error",
},
Command {
name: "server",
cmd: &server::cmd,
run: &server::run,
+ log_level: "info",
},
Command {
name: "watch",
cmd: &watch::cmd,
run: &watch::run,
+ log_level: "error",
},
Command {
name: "record",
cmd: &record::cmd,
run: &record::run,
+ log_level: "error",
},
Command {
name: "play",
cmd: &play::cmd,
run: &play::run,
+ log_level: "error",
},
];
@@ -55,10 +61,17 @@ pub fn parse<'a>() -> Result<clap::ArgMatches<'a>> {
}
pub fn run(matches: &clap::ArgMatches<'_>) -> Result<()> {
+ let mut chosen_cmd = &COMMANDS[0];
+ let mut chosen_submatches = &clap::ArgMatches::<'_>::default();
for cmd in COMMANDS {
if let Some(submatches) = matches.subcommand_matches(cmd.name) {
- return (cmd.run)(submatches);
+ chosen_cmd = cmd;
+ chosen_submatches = submatches;
}
}
- (COMMANDS[0].run)(&clap::ArgMatches::<'_>::default())
+ env_logger::from_env(
+ env_logger::Env::default().default_filter_or(chosen_cmd.log_level),
+ )
+ .init();
+ (chosen_cmd.run)(chosen_submatches)
}
diff --git a/src/main.rs b/src/main.rs
index edba700..20172af 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -27,10 +27,6 @@ mod util;
fn main() {
dirs::Dirs::new().create_all().unwrap();
- env_logger::from_env(
- env_logger::Env::default().default_filter_or("info"),
- )
- .init();
match crate::cmd::parse().and_then(|m| crate::cmd::run(&m)) {
Ok(_) => {}
Err(err) => {