From 7a04539cf473f9b007ea34c1b12d4dd650667485 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 2 Aug 2024 11:28:43 -0400 Subject: [PATCH] feat: use tracing::spans to categorize types of events --- cmd/soroban-cli/src/log/event.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/soroban-cli/src/log/event.rs b/cmd/soroban-cli/src/log/event.rs index a80a897cd..8a4fedfbf 100644 --- a/cmd/soroban-cli/src/log/event.rs +++ b/cmd/soroban-cli/src/log/event.rs @@ -1,12 +1,23 @@ +use tracing::{debug, info, span, Level}; + use crate::xdr; + pub fn events(events: &[xdr::DiagnosticEvent]) { for (i, event) in events.iter().enumerate() { - if is_contract_event(event) { - tracing::info!(event_type = "contract", "{i}: {event:#?}"); + let span = if is_contract_event(event) { + span!(Level::INFO, "contract_event") } else if is_log_event(event) { - tracing::info!(event_type = "log", "{i}: {event:#?}"); + span!(Level::INFO, "log_event") + } else { + span!(Level::DEBUG, "diagnostic_event") + }; + + let _enter = span.enter(); + + if span.metadata().unwrap().level() == &Level::INFO { + info!("{i}: {event:#?}"); } else { - tracing::debug!(event_type = "diagnostic", "{i}: {event:#?}"); + debug!("{i}: {event:#?}"); } } }