Macro soroban_sdk::log
source · macro_rules! log { ($env:expr, $fmt:literal $(,)?) => { ... }; ($env:expr, $fmt:literal, $($args:expr),* $(,)?) => { ... }; }
Expand description
Log a debug event.
Takes a Env, a literal string, and an optional trailing sequence of
arguments that may be any value that are convertible to Val
. The
string and arguments are appended as-is to the log, as the body of a
structured diagnostic event. Such events may be emitted from the host as
auxiliary diagnostic XDR, or converted to strings later for debugging.
log!
statements are only enabled in non optimized builds that have
debug-assertions
enabled. To enable debug-assertions
add the following
lines to Cargo.toml
, then build with the profile specified, --profile release-with-logs
. See the cargo docs for how to use custom profiles.
[profile.release-with-logs]
inherits = "release"
debug-assertions = true
Examples
Log a string:
use soroban_sdk::{log, Env};
let env = Env::default();
log!(&env, "a log entry");
Log a string with values:
use soroban_sdk::{log, symbol_short, Symbol, Env};
let env = Env::default();
let value = 5;
log!(&env, "a log entry", value, symbol_short!("another"));
Assert on logs in tests:
use soroban_sdk::{log, symbol_short, Symbol, Env};
let env = Env::default();
let value = 5;
log!(&env, "a log entry", value, symbol_short!("another"));
use soroban_sdk::testutils::Logs;
let logentry = env.logs().all().last().unwrap().clone();
assert!(logentry.contains("[\"a log entry\", 5, another]"));