Skip to content

Commit 58f571e

Browse files
ple1niduartgomez
authored andcommitted
logging in contract and non contract env
1 parent 9f071a9 commit 58f571e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

rust/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub(crate) mod common_generated {
2626
}
2727

2828
pub mod client_api;
29-
#[cfg(feature = "contract")]
3029
pub mod log;
3130
#[cfg(feature = "contract")]
3231
pub mod rand;

rust/src/log.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
#[macro_export]
2+
macro_rules! info {
3+
($fmt:expr, $($args:tt)*) => {
4+
#[cfg(not(feature="contract"))]
5+
tracing::info!($fmt, $($args)*);
6+
#[cfg(feature="contract")]
7+
info(&format!($fmt, $($args)*));
8+
};
9+
}
10+
111
pub fn info(msg: &str) {
212
let ptr = msg.as_ptr() as _;
313
unsafe {
@@ -10,3 +20,13 @@ extern "C" {
1020
#[doc(hidden)]
1121
fn __frnt__logger__info(id: i64, ptr: i64, len: i32);
1222
}
23+
24+
#[test]
25+
fn log_non_contract() {
26+
use tracing::level_filters::LevelFilter;
27+
28+
tracing_subscriber::FmtSubscriber::builder()
29+
.with_max_level(LevelFilter::INFO)
30+
.init();
31+
info!("n={}, y={:?}", 1, 2);
32+
}

0 commit comments

Comments
 (0)