mem_isolate/
macros.rs

1//! Private macros module for conditional tracing
2//!
3//! This module provides macros that simplify conditional tracing by
4//! squashing the two-line pattern:
5//!
6//! ```
7//! #[cfg(feature = "tracing")]
8//! tracing::debug!("message");
9//! ```
10//!
11//! Into a `debug!` macro call.
12//!
13//! These macros have the same names as the tracing crate's macros,
14//! but they are conditionally compiled based on the "tracing" feature.
15#![allow(unused_imports)]
16#![allow(unused_macros)]
17
18/// Conditionally emits a trace-level log message when the "tracing" feature is enabled.
19///
20/// This macro does nothing when the "tracing" feature is disabled.
21#[macro_export]
22macro_rules! trace {
23    ($($arg:tt)*) => {
24        #[cfg(feature = "tracing")]
25        tracing::trace!($($arg)*);
26    };
27}
28
29/// Conditionally emits a debug-level log message when the "tracing" feature is enabled.
30///
31/// This macro does nothing when the "tracing" feature is disabled.
32macro_rules! debug {
33    ($($arg:tt)*) => {
34        #[cfg(feature = "tracing")]
35        tracing::debug!($($arg)*);
36    };
37}
38
39/// Conditionally emits an info-level log message when the "tracing" feature is enabled.
40///
41/// This macro does nothing when the "tracing" feature is disabled.
42macro_rules! info {
43    ($($arg:tt)*) => {
44        #[cfg(feature = "tracing")]
45        tracing::info!($($arg)*);
46    };
47}
48
49/// Conditionally emits a warn-level log message when the "tracing" feature is enabled.
50///
51/// This macro does nothing when the "tracing" feature is disabled.
52macro_rules! warning {
53    ($($arg:tt)*) => {
54        #[cfg(feature = "tracing")]
55        tracing::warn!($($arg)*);
56    };
57}
58
59/// Conditionally emits an error-level log message when the "tracing" feature is enabled.
60///
61/// This macro does nothing when the "tracing" feature is disabled.
62macro_rules! error {
63    ($($arg:tt)*) => {
64        #[cfg(feature = "tracing")]
65        tracing::error!($($arg)*);
66    };
67}
68
69pub(crate) use {debug, error, info, trace, warning};