From 75ace42366b9dbe7230f94310564662c496a69a0 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 3 Apr 2024 19:21:03 +0300 Subject: [PATCH] lightclient: Trim response for logs Signed-off-by: Alexandru Vasile --- lightclient/src/background.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lightclient/src/background.rs b/lightclient/src/background.rs index 0ae565b1de..d8c4648ddb 100644 --- a/lightclient/src/background.rs +++ b/lightclient/src/background.rs @@ -242,6 +242,12 @@ struct ActiveSubscription { unsubscribe_method: String, } +fn trim_response(response: &str) -> &str { + const MAX_RESPONSE_SIZE: usize = 256; + let len = std::cmp::min(response.len(), MAX_RESPONSE_SIZE); + &response[..len] +} + impl BackgroundTaskData { /// Fetch and increment the request ID. fn next_id(&mut self) -> usize { @@ -359,7 +365,7 @@ impl BackgroundTaskData { /// Parse the response received from the light client and sent it to the appropriate user. fn handle_rpc_response(&mut self, response: String) { let chain_id = self.chain_id; - tracing::trace!(target: LOG_TARGET, "Received from smoldot response='{response}' chain={chain_id:?}"); + tracing::trace!(target: LOG_TARGET, "Received from smoldot response='{}' chain={chain_id:?}", trim_response(&response)); match RpcResponse::from_str(&response) { Ok(RpcResponse::Method { id, result }) => {