Skip to content

Commit

Permalink
feat: use tracing::spans to categorize types of events
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Aug 2, 2024
1 parent 9649329 commit 7a04539
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/soroban-cli/src/log/event.rs
Original file line number Diff line number Diff line change
@@ -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:#?}");
}
}
}
Expand Down

0 comments on commit 7a04539

Please sign in to comment.