From dbc74a8efa85415096af0a9a1e6d49fdf6a558ca Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 12 Sep 2024 09:51:34 +1000 Subject: [PATCH 1/3] Change output of events in logs from Rust debug to JSON --- cmd/soroban-cli/src/log/event.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/soroban-cli/src/log/event.rs b/cmd/soroban-cli/src/log/event.rs index 8a4fedfbf..3945ae999 100644 --- a/cmd/soroban-cli/src/log/event.rs +++ b/cmd/soroban-cli/src/log/event.rs @@ -1,4 +1,4 @@ -use tracing::{debug, info, span, Level}; +use tracing::{debug, error, info, span, Level}; use crate::xdr; @@ -14,10 +14,16 @@ pub fn events(events: &[xdr::DiagnosticEvent]) { let _enter = span.enter(); - if span.metadata().unwrap().level() == &Level::INFO { - info!("{i}: {event:#?}"); - } else { - debug!("{i}: {event:#?}"); + let result = serde_json::to_string(event); + match result { + Ok(json) => { + if span.metadata().unwrap().level() == &Level::INFO { + info!("{i}: {json}"); + } else { + debug!("{i}: {json}"); + } + } + Err(err) => error!("converting event to json: {}: ", err), } } } From da7a3f66a3b8569ad9fa5300efb6632c8f254a94 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 12 Sep 2024 10:04:27 +1000 Subject: [PATCH 2/3] simplify --- cmd/soroban-cli/src/log/event.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cmd/soroban-cli/src/log/event.rs b/cmd/soroban-cli/src/log/event.rs index 3945ae999..4ff7debb9 100644 --- a/cmd/soroban-cli/src/log/event.rs +++ b/cmd/soroban-cli/src/log/event.rs @@ -1,6 +1,7 @@ -use tracing::{debug, error, info, span, Level}; +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() { @@ -14,16 +15,12 @@ pub fn events(events: &[xdr::DiagnosticEvent]) { let _enter = span.enter(); - let result = serde_json::to_string(event); - match result { - Ok(json) => { - if span.metadata().unwrap().level() == &Level::INFO { - info!("{i}: {json}"); - } else { - debug!("{i}: {json}"); - } - } - Err(err) => error!("converting event to json: {}: ", err), + 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}: {xdr} {json}"); + } else { + debug!("{i}: {xdr} {json}"); } } } From 9c6ec58664020d46f2965801e7bcd5651ad3c990 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Wed, 18 Sep 2024 21:33:56 +1000 Subject: [PATCH 3/3] fix --- .../soroban-test/tests/it/integration/hello_world.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs index 20b680997..e523efb8f 100644 --- a/cmd/crates/soroban-test/tests/it/integration/hello_world.rs +++ b/cmd/crates/soroban-test/tests/it/integration/hello_world.rs @@ -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")); }