Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change output of events in logs from Rust debug to JSON #1600

Merged
merged 4 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading