Skip to content

Commit

Permalink
tx/vp_prelude: improve debug_log! macro
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jul 21, 2022
1 parent 6ffc13f commit 76e1458
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
26 changes: 19 additions & 7 deletions tx_prelude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@

pub use anoma_vm_env::tx_prelude::*;

/// Log a string in a debug build. The message will be printed at the
/// `tracing::Level::Info`. Any `debug_log!` statements are only enabled in
/// non optimized builds by default. An optimized build will not execute
/// `debug_log!` statements unless `-C debug-assertions` is passed to the
/// compiler.
/// Format and log a string in a debug build.
///
/// In WASM target debug build, the message will be printed at the
/// `tracing::Level::Info` when executed in the VM. An optimized build will
/// omit any `debug_log!` statements unless `-C debug-assertions` is passed to
/// the compiler.
///
/// In non-WASM target, the message is simply printed out to stdout.
#[macro_export]
macro_rules! debug_log {
($($arg:tt)*) => {{
(if cfg!(debug_assertions) { log_string(format!($($arg)*)) })
}}
(
if cfg!(target_arch = "wasm32") {
if cfg!(debug_assertions)
{
log_string(format!($($arg)*));
}
} else {
println!($($arg)*);
}
)
}};
}
26 changes: 19 additions & 7 deletions vp_prelude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@ pub fn is_vp_whitelisted(vp_bytes: &[u8]) -> bool {
whitelist.is_empty() || whitelist.contains(&vp_hash.to_string())
}

/// Log a string in a debug build. The message will be printed at the
/// `tracing::Level::Info`. Any `debug_log!` statements are only enabled in
/// non optimized builds by default. An optimized build will not execute
/// `debug_log!` statements unless `-C debug-assertions` is passed to the
/// compiler.
/// Format and log a string in a debug build.
///
/// In WASM target debug build, the message will be printed at the
/// `tracing::Level::Info` when executed in the VM. An optimized build will
/// omit any `debug_log!` statements unless `-C debug-assertions` is passed to
/// the compiler.
///
/// In non-WASM target, the message is simply printed out to stdout.
#[macro_export]
macro_rules! debug_log {
($($arg:tt)*) => {{
(if cfg!(debug_assertions) { log_string(format!($($arg)*)) })
}}
(
if cfg!(target_arch = "wasm32") {
if cfg!(debug_assertions)
{
log_string(format!($($arg)*));
}
} else {
println!($($arg)*);
}
)
}};
}

0 comments on commit 76e1458

Please sign in to comment.