From 9e8f5f028b2a53595fc7da09472546126af92e74 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 18 Nov 2020 21:24:17 +0000 Subject: [PATCH] show command errors in debug trace Signed-off-by: Ian Jackson --- src/cmdlistener.rs | 24 ++++++++++++++++++------ src/imports.rs | 2 +- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index edddfdfc..b17e7382 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -69,8 +69,6 @@ type PCH = PermissionCheckHow; #[throws(ME)] fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse { - info!("command connection {}: executing {:?}", &cs.desc, &cmd); - match cmd { Noop => Fine, @@ -715,10 +713,24 @@ impl CommandStream<'_> { pub fn mainloop(mut self) { loop { use MgmtChannelReadError::*; - let resp = match self.chan.read() { - Ok(cmd) => match execute(&mut self, cmd) { - Ok(resp) => resp, - Err(error) => MgmtResponse::Error { error }, + let resp = match self.chan.read::() { + Ok(cmd) => { + let cmd_s = + log_enabled!(log::Level::Info) + .as_some_from(|| format!("{:?}", &cmd)) + .unwrap_or_default(); + match execute(&mut self, cmd) { + Ok(resp) => { + info!("command connection {}: executed {:?}", + &self.desc, cmd_s); + resp + }, + Err(error) => { + info!("command connection {}: error {:?} from {:?}", + &self.desc, &error, cmd_s); + MgmtResponse::Error { error } + }, + } }, Err(EOF) => break, Err(IO(e)) => Err(e).context("read command stream")?, diff --git a/src/imports.rs b/src/imports.rs index c2c673f3..6d4d575e 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -86,7 +86,7 @@ pub use regex::Regex; pub use arrayvec::ArrayVec; pub use log::{trace,debug,info,warn,error}; -pub use log::log; +pub use log::{log, log_enabled}; pub use num_traits::{Bounded, FromPrimitive, ToPrimitive}; -- 2.30.2