Skip to content
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
90 changes: 15 additions & 75 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,107 +3,47 @@
//! When the `tracing` feature is disabled, all logging calls compile to no-ops,
//! ensuring zero runtime cost for users who don't need observability.

#[cfg(feature = "tracing")]
#[allow(unused_macros)]
macro_rules! error {
($($arg:tt)*) => {
tracing::error!(target: "event_scanner", $($arg)*)
if cfg!(feature = "tracing") {
tracing::error!(target: "event_scanner", $($arg)*)
}
};
}

#[cfg(not(feature = "tracing"))]
#[allow(unused_macros)]
macro_rules! error {
($($arg:tt)*) => {
$crate::__trace_consume!($($arg)*)
};
}

#[cfg(feature = "tracing")]
#[allow(unused_macros)]
macro_rules! warn {
($($arg:tt)*) => {
tracing::warn!(target: "event_scanner", $($arg)*)
if cfg!(feature = "tracing") {
tracing::warn!(target: "event_scanner", $($arg)*)
}
};
}

#[cfg(not(feature = "tracing"))]
#[allow(unused_macros)]
macro_rules! warn {
($($arg:tt)*) => {
$crate::__trace_consume!($($arg)*)
};
}

#[cfg(feature = "tracing")]
#[allow(unused_macros)]
macro_rules! info {
($($arg:tt)*) => {
tracing::info!(target: "event_scanner", $($arg)*)
if cfg!(feature = "tracing") {
tracing::info!(target: "event_scanner", $($arg)*)
}
};
}

#[cfg(not(feature = "tracing"))]
#[allow(unused_macros)]
macro_rules! info {
($($arg:tt)*) => {
$crate::__trace_consume!($($arg)*)
};
}

#[cfg(feature = "tracing")]
#[allow(unused_macros)]
macro_rules! debug {
($($arg:tt)*) => {
tracing::debug!(target: "event_scanner", $($arg)*)
if cfg!(feature = "tracing") {
tracing::debug!(target: "event_scanner", $($arg)*)
}
};
}

#[cfg(not(feature = "tracing"))]
#[allow(unused_macros)]
macro_rules! debug {
($($arg:tt)*) => {
$crate::__trace_consume!($($arg)*)
};
}

#[cfg(feature = "tracing")]
#[allow(unused_macros)]
macro_rules! trace {
($($arg:tt)*) => {
tracing::trace!(target: "event_scanner", $($arg)*)
};
}

#[cfg(not(feature = "tracing"))]
#[allow(unused_macros)]
macro_rules! trace {
($($arg:tt)*) => {
$crate::__trace_consume!($($arg)*)
};
}

#[doc(hidden)]
#[macro_export]
#[cfg(not(feature = "tracing"))]
#[allow(unused_macros)]
macro_rules! __trace_consume {
// field = %expr, rest...
($field:ident = % $value:expr, $($rest:tt)*) => {
{ let _ = &$value; $crate::__trace_consume!($($rest)*); }
};
// field = ?expr, rest...
($field:ident = ? $value:expr, $($rest:tt)*) => {
{ let _ = &$value; $crate::__trace_consume!($($rest)*); }
};
// field = expr, rest...
($field:ident = $value:expr, $($rest:tt)*) => {
{ let _ = &$value; $crate::__trace_consume!($($rest)*); }
};
// String literal or other tokens - ignore
($lit:literal $($rest:tt)*) => {
$crate::__trace_consume!($($rest)*)
if cfg!(feature = "tracing") {
tracing::trace!(target: "event_scanner", $($arg)*)
}
};
// Base case - empty
() => {};
}