From 6cb1fb7eba04c5317ba303aa4ff08c4d0863cb79 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 10 Oct 2021 12:01:48 +0200 Subject: [PATCH] Add more logging Signed-off-by: trivernis --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/events/event.rs | 1 + src/ipc/client.rs | 1 + src/ipc/mod.rs | 5 +++++ src/ipc/server.rs | 1 + src/ipc/stream_emitter.rs | 3 +++ 7 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fad54f39..02abeb37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,7 +148,7 @@ dependencies = [ [[package]] name = "rmp-ipc" -version = "0.4.1" +version = "0.4.2" dependencies = [ "lazy_static", "log", diff --git a/Cargo.toml b/Cargo.toml index a7faacf3..06c40691 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rmp-ipc" -version = "0.4.1" +version = "0.4.2" authors = ["trivernis "] edition = "2018" readme = "README.md" diff --git a/src/events/event.rs b/src/events/event.rs index aeaaac6e..cbc694bf 100644 --- a/src/events/event.rs +++ b/src/events/event.rs @@ -69,6 +69,7 @@ impl Event { /// Reads an event message pub async fn from_async_read(reader: &mut R) -> Result { let length = reader.read_u32().await?; + log::trace!("Parsing event of length {}", length); let mut data = vec![0u8; length as usize]; reader.read_exact(&mut data).await?; let event = rmp_serde::from_read(&data[..])?; diff --git a/src/ipc/client.rs b/src/ipc/client.rs index c9071566..b1795984 100644 --- a/src/ipc/client.rs +++ b/src/ipc/client.rs @@ -32,6 +32,7 @@ impl IPCClient { ); let handler = Arc::new(self.handler); let namespaces = Arc::new(self.namespaces); + log::debug!("IPC client connected to {}", address); tokio::spawn({ let ctx = Context::clone(&ctx); diff --git a/src/ipc/mod.rs b/src/ipc/mod.rs index a68b59bf..b48662f0 100644 --- a/src/ipc/mod.rs +++ b/src/ipc/mod.rs @@ -21,9 +21,11 @@ async fn handle_connection( ctx: Context, ) { while let Ok(event) = Event::from_async_read(&mut read_half).await { + log::debug!("Received {:?}:{} event", event.namespace(), event.name()); // check if the event is a reply if let Some(ref_id) = event.reference_id() { // get the listener for replies + log::trace!("Event is response to {}", ref_id); if let Some(sender) = ctx.get_reply_sender(ref_id).await { // try sending the event to the listener for replies if let Err(event) = sender.send(event) { @@ -31,11 +33,14 @@ async fn handle_connection( } continue; } + log::trace!("No response listener found for event. Passing to regular listener."); } if let Some(namespace) = event.namespace().clone().and_then(|n| namespaces.get(&n)) { + log::trace!("Passing event to namespace listener"); let handler = Arc::clone(&namespace.handler); handle_event(Context::clone(&ctx), handler, event); } else { + log::trace!("Passing event to global listener"); handle_event(Context::clone(&ctx), Arc::clone(&handler), event); } } diff --git a/src/ipc/server.rs b/src/ipc/server.rs index 5de5f9b2..1fa3e5ca 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -27,6 +27,7 @@ impl IPCServer { let handler = Arc::new(self.handler); let namespaces = Arc::new(self.namespaces); let data = Arc::new(RwLock::new(self.data)); + log::debug!("IPC server listening on {}", address); while let Ok((stream, _)) = listener.accept().await { let handler = Arc::clone(&handler); diff --git a/src/ipc/stream_emitter.rs b/src/ipc/stream_emitter.rs index a680385a..6da3dfa8 100644 --- a/src/ipc/stream_emitter.rs +++ b/src/ipc/stream_emitter.rs @@ -30,6 +30,8 @@ impl StreamEmitter { res_id: Option, ) -> Result { let data_bytes = rmp_serde::to_vec(&data)?; + log::debug!("Emitting event {:?}:{}", namespace, event); + let event = if let Some(namespace) = namespace { Event::with_namespace(namespace.to_string(), event.to_string(), data_bytes, res_id) } else { @@ -38,6 +40,7 @@ impl StreamEmitter { let event_bytes = event.to_bytes()?; { + log::trace!("Writing {} bytes", event_bytes.len()); let mut stream = self.stream.lock().await; (*stream).write_all(&event_bytes[..]).await?; }