From 8907a3390781bf0ddcb91bcba52b245492a718f2 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Tue, 27 Oct 2020 11:21:49 +0000 Subject: [PATCH] agent: Only show ttrpc logs for trace log level Only display the `ttrpc` crate log output when full logging (trace level) is enabled. This is a slight abuse of log levels but provides developers and testers what they need whilst also keeping the logs relatively quiet for the default info log level (the `ttrpc` crate logging is a bit "chatty"). Signed-off-by: James O. D. Hunt --- src/agent/Cargo.lock | 1 + src/agent/Cargo.toml | 1 + src/agent/src/main.rs | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index b99febaa6..a8cf99d9e 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -375,6 +375,7 @@ dependencies = [ "cgroups", "lazy_static", "libc", + "log", "logging", "netlink", "nix 0.17.0", diff --git a/src/agent/Cargo.toml b/src/agent/Cargo.toml index 28d19c04b..c280211a4 100644 --- a/src/agent/Cargo.toml +++ b/src/agent/Cargo.toml @@ -30,6 +30,7 @@ slog-scope = "4.1.2" # Redirect ttrpc log calls slog-stdlog = "4.0.0" +log = "0.4.11" # for testing tempfile = "3.1.0" diff --git a/src/agent/src/main.rs b/src/agent/src/main.rs index 92d87374f..dddb083ba 100644 --- a/src/agent/src/main.rs +++ b/src/agent/src/main.rs @@ -198,8 +198,12 @@ fn main() -> Result<()> { // which is required to satisfy the the lifetime constraints of the auto-generated gRPC code. let _guard = slog_scope::set_global_logger(logger.new(o!("subsystem" => "rpc"))); - // Redirect ttrpc log calls to slog - let _log_guard = slog_stdlog::init()?; + let mut _log_guard: Result<(), log::SetLoggerError> = Ok(()); + + if config.log_level == slog::Level::Trace { + // Redirect ttrpc log calls to slog iff full debug requested + _log_guard = Ok(slog_stdlog::init().map_err(|e| e)?); + } start_sandbox(&logger, &config, init_mode)?;