Skip to content
Open
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub(crate) mod common_generated {
}

pub mod client_api;
#[cfg(feature = "contract")]
pub mod log;
#[cfg(feature = "contract")]
pub mod rand;
Expand Down
21 changes: 21 additions & 0 deletions rust/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#[macro_export]
macro_rules! info {
($($arg:tt)*) => {
#[cfg(not(feature = "contract"))]
tracing::info!($($arg)*);
#[cfg(feature = "contract")]
::freenet_stdlib::log::info(&format!($($arg)*));
};
}

pub fn info(msg: &str) {
let ptr = msg.as_ptr() as _;
unsafe {
Expand All @@ -10,3 +20,14 @@ extern "C" {
#[doc(hidden)]
fn __frnt__logger__info(id: i64, ptr: i64, len: i32);
}

#[test]
fn log_non_contract() {
use tracing::level_filters::LevelFilter;

tracing_subscriber::FmtSubscriber::builder()
.with_max_level(LevelFilter::INFO)
.init();
info!("n={}, y={:?}", 1, 2);
info!("zk");
}
Loading