chiark / gitweb /
show command errors in debug trace
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 18 Nov 2020 21:24:17 +0000 (21:24 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 18 Nov 2020 21:24:30 +0000 (21:24 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/cmdlistener.rs
src/imports.rs

index edddfdfce37afee52d310fd3627a5f4f9ccd1840..b17e7382c8376e3425d2f7d5808c3684ddab52e5 100644 (file)
@@ -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::<MgmtCommand>() {
+        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")?,
index c2c673f3c2edb52da84fe7388bea5a2e97d05aad..6d4d575ed2c1a5de9aa6f1cb1ec0d5fca33cf25f 100644 (file)
@@ -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};