From e7cd2555875becff488bd2db01986f21bfe40cd2 Mon Sep 17 00:00:00 2001 From: binarybaron <86064887+binarybaron@users.noreply.github.com> Date: Sat, 2 Dec 2023 01:23:59 +0100 Subject: [PATCH] Log event loop connection properties as tracing fields --- swap/src/api/request.rs | 2 +- swap/src/cli/event_loop.rs | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/swap/src/api/request.rs b/swap/src/api/request.rs index 50e29dca..f6eebf2d 100644 --- a/swap/src/api/request.rs +++ b/swap/src/api/request.rs @@ -834,7 +834,7 @@ impl Request { .await .map_err(|err| { method_span.in_scope(|| { - tracing::debug!(err=format!("{:?}", err), "API call resulted in an error"); + tracing::debug!(err = format!("{:?}", err), "API call resulted in an error"); }); err }) diff --git a/swap/src/cli/event_loop.rs b/swap/src/cli/event_loop.rs index 5217b688..23aa0f38 100644 --- a/swap/src/cli/event_loop.rs +++ b/swap/src/cli/event_loop.rs @@ -151,17 +151,17 @@ impl EventLoop { return; } SwarmEvent::Behaviour(OutEvent::Failure { peer, error }) => { - tracing::warn!(%peer, "Communication error: {:#}", error); + tracing::warn!(%peer, err = %error, "Communication error"); return; } SwarmEvent::ConnectionEstablished { peer_id, endpoint, .. } if peer_id == self.alice_peer_id => { - tracing::info!("Connected to Alice at {}", endpoint.get_remote_address()); + tracing::info!(peer_id = %endpoint.get_remote_address(), "Connected to Alice"); } SwarmEvent::Dialing(peer_id) if peer_id == self.alice_peer_id => { - tracing::debug!("Dialling Alice at {}", peer_id); + tracing::debug!(%peer_id, "Dialling Alice"); } SwarmEvent::ConnectionClosed { peer_id, endpoint, num_established, cause: Some(error) } if peer_id == self.alice_peer_id && num_established == 0 => { - tracing::warn!("Lost connection to Alice at {}, cause: {}", endpoint.get_remote_address(), error); + tracing::warn!(peer_id = %endpoint.get_remote_address(), cause = %error, "Lost connection to Alice"); } SwarmEvent::ConnectionClosed { peer_id, num_established, cause: None, .. } if peer_id == self.alice_peer_id && num_established == 0 => { // no error means the disconnection was requested @@ -169,10 +169,10 @@ impl EventLoop { return; } SwarmEvent::OutgoingConnectionError { peer_id, error } if matches!(peer_id, Some(alice_peer_id) if alice_peer_id == self.alice_peer_id) => { - tracing::warn!( "Failed to dial Alice: {}", error); + tracing::warn!(%error, "Failed to dial Alice"); if let Some(duration) = self.swarm.behaviour_mut().redial.until_next_redial() { - tracing::info!("Next redial attempt in {}s", duration.as_secs()); + tracing::info!(seconds_until_next_redial = %duration.as_secs(), "Waiting for next redial attempt"); } }