Skip to content

Commit

Permalink
Change output of events in logs from Rust debug to JSON (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch authored Sep 18, 2024
1 parent 62ae1d7 commit 0a0cac0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cmd/crates/soroban-test/tests/it/integration/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,12 @@ fn invoke_log(sandbox: &TestEnv, id: &str) {
.assert()
.success()
.stderr(predicates::str::contains(
"INFO contract_event: soroban_cli::log::event: 1: DiagnosticEvent {",
"INFO contract_event: soroban_cli::log::event: 1:",
))
.stderr(predicates::str::contains("StringM(hello)"))
.stderr(predicates::str::contains("hello"))
.stderr(predicates::str::contains(
"INFO log_event: soroban_cli::log::event: 2: DiagnosticEvent",
"INFO log_event: soroban_cli::log::event: 2:",
))
.stderr(predicates::str::contains("StringM(hello {})"))
.stderr(predicates::str::contains("StringM(world)"));
.stderr(predicates::str::contains("hello {}"))
.stderr(predicates::str::contains("world"));
}
7 changes: 5 additions & 2 deletions cmd/soroban-cli/src/log/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use tracing::{debug, info, span, Level};

use crate::xdr;
use xdr::WriteXdr;

pub fn events(events: &[xdr::DiagnosticEvent]) {
for (i, event) in events.iter().enumerate() {
Expand All @@ -14,10 +15,12 @@ pub fn events(events: &[xdr::DiagnosticEvent]) {

let _enter = span.enter();

let xdr = event.to_xdr_base64(xdr::Limits::none()).unwrap();
let json = serde_json::to_string(event).unwrap();
if span.metadata().unwrap().level() == &Level::INFO {
info!("{i}: {event:#?}");
info!("{i}: {xdr} {json}");
} else {
debug!("{i}: {event:#?}");
debug!("{i}: {xdr} {json}");
}
}
}
Expand Down

0 comments on commit 0a0cac0

Please sign in to comment.