From 4e1e64d1b9cfe66699a308ba615e1b71908b63ee Mon Sep 17 00:00:00 2001 From: Alex Mikhalev Date: Wed, 30 Sep 2020 14:41:09 -0600 Subject: [PATCH] Improve mqtt request logging --- src/mqtt/actor.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mqtt/actor.rs b/src/mqtt/actor.rs index b5c7165..65d8558 100644 --- a/src/mqtt/actor.rs +++ b/src/mqtt/actor.rs @@ -1,6 +1,6 @@ use super::{event_loop::EventLoopTask, request, MqttInterface}; use actix::{Actor, ActorContext, ActorFuture, AsyncContext, Handler, WrapFuture}; -use request::{ErrorCode, RequestContext, RequestError, WithRequestId}; +use request::{ErrorCode, RequestContext, RequestError, WithRequestId, Response}; use tokio::sync::oneshot; use tracing::{debug, error, info, trace, warn}; @@ -37,7 +37,7 @@ impl MqttActor { let rid = request_value.rid; let request_fut = serde_json::from_value::(request_value.rest).map(|mut request| { - trace!("deserialized request: {:?}", request); + debug!(rid, "about to execute request: {:?}", request); request.execute(&mut self.request_context) }); let mut interface = self.interface.clone(); @@ -52,11 +52,18 @@ impl MqttActor { ) .into(), }; + match &response { + Response::Success(res) => { + debug!(rid, response = display(res), "success response:"); + }, + Response::Error(err) => { + debug!(rid, "request error: {}", err); + } + }; let resp_with_id = WithRequestId:: { rid, rest: response, }; - trace!("sending request response: {:?}", resp_with_id); if let Err(err) = interface.publish_response(resp_with_id).await { error!("could not publish request response: {:?}", err); } @@ -134,7 +141,6 @@ impl Handler for MqttActor { fn handle(&mut self, msg: PubRecieve, ctx: &mut Self::Context) -> Self::Result { let topic = &msg.0.topic; if topic == &self.interface.topics.requests() { - debug!("received request: {:?}", msg.0); self.handle_request(msg.0.payload.as_ref(), ctx); } else { warn!("received on unknown topic: {:?}", topic);