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

fix: Make log macro fully compatible with std::format #1189

Merged
merged 1 commit into from
Jun 4, 2024
Merged
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
9 changes: 3 additions & 6 deletions near-sdk/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub(crate) use cache_entry::{CacheEntry, EntryState};
use crate::{env, NearToken, PromiseResult};

/// Helper macro to log a message through [`env::log_str`].
/// This macro can be used similar to the [`std::format`] macro in most cases.
/// This macro can be used similar to the [`std::format`] macro.
///
/// This differs from [`std::format`] because instead of generating a string, it will log the utf8
/// bytes as a log through [`env::log_str`].
Expand All @@ -25,7 +25,7 @@ use crate::{env, NearToken, PromiseResult};
/// # fn main() {
/// log!("test");
/// let world: &str = "world";
/// log!(world);
/// log!("{world}");
/// log!("Hello {}", world);
/// log!("x = {}, y = {y}", 10, y = 30);
/// # }
Expand All @@ -34,11 +34,8 @@ use crate::{env, NearToken, PromiseResult};
/// [`env::log_str`]: crate::env::log_str
#[macro_export]
macro_rules! log {
($arg:expr) => {
$crate::env::log_str($arg.as_ref())
};
($($arg:tt)*) => {
$crate::env::log_str(format!($($arg)*).as_str())
$crate::env::log_str(::std::format!($($arg)*).as_str())
};
}

Expand Down
Loading