From 168a3fd34824adc9c6a606cd144219701f15cccf Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Wed, 17 Dec 2025 21:23:46 -0500 Subject: [Rust] Replace `log` with `tracing` - Added more documentation - Replaced global named logger for plugins, fixing the issue when the CU has multiple (e.g. statically linked demo) - Simplified some misc code This is a breaking change, but I believe there is no better time to make it, we cannot continue to use the `log` crate, it is too limited for our needs. --- rust/src/ffi.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'rust/src/ffi.rs') diff --git a/rust/src/ffi.rs b/rust/src/ffi.rs index d337df34..b6124dd4 100644 --- a/rust/src/ffi.rs +++ b/rust/src/ffi.rs @@ -20,7 +20,7 @@ macro_rules! ffi_wrap { use std::process; panic::catch_unwind(|| $b).unwrap_or_else(|_| { - log::error!("ffi callback caught panic: {}", $n); + tracing::error!("ffi callback caught panic: {}", $n); process::abort() }) }}; @@ -30,3 +30,41 @@ pub(crate) fn time_from_bn(timestamp: u64) -> SystemTime { let m = Duration::from_secs(timestamp); UNIX_EPOCH + m } + +#[macro_export] +macro_rules! ffi_span { + ($name:expr, $bv:expr) => {{ + use $crate::binary_view::BinaryViewExt; + #[allow(unused_imports)] + use $crate::file_metadata::FileMetadata; + tracing::info_span!($name, session_id = $bv.file().session_id().0).entered() + }}; + ($name:expr) => { + tracing::info_span!($name).entered() + }; +} + +macro_rules! new_id_type { + ($name:ident, $inner_type:ty) => { + #[derive(std::fmt::Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] + pub struct $name(pub $inner_type); + + impl From<$inner_type> for $name { + fn from(value: $inner_type) -> Self { + Self(value) + } + } + + impl From<$name> for $inner_type { + fn from(value: $name) -> Self { + value.0 + } + } + + impl std::fmt::Display for $name { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) + } + } + }; +} -- cgit v1.3.1