From fe9f0b04294330bb9987ba97b9d728957522ed85 Mon Sep 17 00:00:00 2001 From: Yiannis Marangos Date: Wed, 12 Jun 2024 14:53:58 +0300 Subject: [PATCH] feat: Change all error/warn logs to debug (#47) --- src/cid_prefix.rs | 4 ++-- src/client.rs | 4 ++-- src/incoming_stream.rs | 17 ++++++++++------- src/server.rs | 6 +++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/cid_prefix.rs b/src/cid_prefix.rs index 99acdec..3a0dfa7 100644 --- a/src/cid_prefix.rs +++ b/src/cid_prefix.rs @@ -1,5 +1,5 @@ use cid::{CidGeneric, Version}; -use tracing::error; +use tracing::debug; use crate::multihasher::{MultihasherError, MultihasherTable}; @@ -89,7 +89,7 @@ impl CidPrefix { data: &[u8], ) -> Result, MultihasherError> { if self.multihash_size > S { - error!( + debug!( "Multihash<{}> can not hold multihash of size {}", S, self.multihash_size ); diff --git a/src/client.rs b/src/client.rs index d655d04..e84670f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -20,7 +20,7 @@ use libp2p_swarm::{ ConnectionHandlerEvent, ConnectionId, NotifyHandler, StreamProtocol, SubstreamProtocol, ToSwarm, }; use smallvec::SmallVec; -use tracing::warn; +use tracing::debug; use crate::incoming_stream::ClientMessage; use crate::message::Codec; @@ -570,7 +570,7 @@ impl ClientConnectionHandler { } fn close_sink_on_error(&mut self, location: &str) { - warn!("sink operation failed, closing: {location}"); + debug!("sink operation failed, closing: {location}"); self.sink_state = SinkState::None; } diff --git a/src/incoming_stream.rs b/src/incoming_stream.rs index 28b458e..5cb199a 100644 --- a/src/incoming_stream.rs +++ b/src/incoming_stream.rs @@ -8,7 +8,7 @@ use cid::CidGeneric; use fnv::FnvHashMap; use futures_util::future::{BoxFuture, Fuse, FusedFuture, FutureExt}; use futures_util::stream::StreamExt; -use tracing::error; +use tracing::debug; use crate::cid_prefix::CidPrefix; use crate::message::Codec; @@ -87,7 +87,7 @@ impl futures_core::stream::Stream for IncomingStream { let msg = match self.stream.poll_next_unpin(cx) { Poll::Ready(Some(Ok(msg))) => msg, Poll::Ready(Some(Err(e))) => { - error!("Message decoding failed: {e}"); + debug!("Message decoding failed: {e}"); return Poll::Ready(None); } Poll::Ready(None) => return Poll::Ready(None), @@ -116,7 +116,7 @@ async fn process_message( let cid = match CidGeneric::try_from(&block_presence.cid[..]) { Ok(cid) => cid, Err(e) => { - error!("Invalid CID bytes: {}: {:?}", e, block_presence.cid); + debug!("Invalid CID bytes: {}: {:?}", e, block_presence.cid); return None; } }; @@ -130,23 +130,26 @@ async fn process_message( for payload in msg.payload { let Some(cid_prefix) = CidPrefix::from_bytes(&payload.prefix) else { - error!("block.prefix not decodable: {:?}", payload.prefix); + debug!("block.prefix not decodable: {:?}", payload.prefix); return None; }; let cid = match cid_prefix.to_cid(&multihasher, &payload.data).await { Ok(cid) => cid, Err(MultihasherError::UnknownMultihashCode) => { - error!("Unknown multihash code: {}", cid_prefix.multihash_code()); + debug!( + "Multihasher non-fatal error: Unknown multihash code: {}", + cid_prefix.multihash_code() + ); continue; } Err(MultihasherError::Custom(e)) => { - error!("{e}"); + debug!("Multihasher non-fatal error: {e}"); continue; } // Any other error is fatal and we need to close the stream. Err(e) => { - error!("{e}"); + debug!("Multihasher fatal error: {e}"); return None; } }; diff --git a/src/server.rs b/src/server.rs index e778bdf..71b45a0 100644 --- a/src/server.rs +++ b/src/server.rs @@ -16,7 +16,7 @@ use libp2p_swarm::{ ConnectionHandlerEvent, NotifyHandler, StreamProtocol, SubstreamProtocol, ToSwarm, }; use smallvec::SmallVec; -use tracing::{debug, trace, warn}; +use tracing::{debug, trace}; use crate::incoming_stream::ServerMessage; use crate::message::Codec; @@ -271,7 +271,7 @@ where self.outgoing_queue.push_back((cid, data)); } Err(e) => { - warn!("Fetching {cid} from blockstore failed: {e}"); + debug!("Fetching {cid} from blockstore failed: {e}"); } } } @@ -393,7 +393,7 @@ impl ServerConnectionHandler { } fn close_sink_on_error(&mut self, location: &str) { - warn!("sink operation failed, closing: {location}"); + debug!("sink operation failed, closing: {location}"); self.sink = SinkState::None; }