diff --git a/src/lib.rs b/src/lib.rs index 7de04debc3..319ddc9c07 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,8 @@ pub use crate::error::{Error, Result}; #[macro_use] mod cfg; #[macro_use] +mod trace; +#[macro_use] mod common; pub mod body; mod error; diff --git a/src/trace.rs b/src/trace.rs new file mode 100644 index 0000000000..c001e4092f --- /dev/null +++ b/src/trace.rs @@ -0,0 +1,107 @@ +#![allow(unused_macros)] + +macro_rules! debug { + ($($arg:tt)+) => { + #[cfg(feature = "tracing")] + { + println!($($arg)+); + tracing::debug!($($arg)+); + } + } +} + +macro_rules! debug_span { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + let span = tracing::debug_span!($($arg)+); + let _ = span.enter(); + } + } +} + +macro_rules! error { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + tracing::error!($($arg)+); + } + } +} + +macro_rules! error_span { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + let span = tracing::error_span!($($arg)+); + let _ = span.enter(); + } + } +} + +macro_rules! info { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + tracing::info!($($arg)+); + } + } +} + +macro_rules! info_span { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + let span = tracing::info_span!($($arg)+); + let _ = span.enter(); + } + } +} + +macro_rules! trace { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + tracing::trace!($($arg)+); + } + } +} + +macro_rules! trace_span { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + let span = tracing::trace_span!($($arg)+); + let _ = span.enter(); + } + } +} + +macro_rules! span { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + let span = tracing::span!($($arg)+); + let _ = span.enter(); + } + } +} + +macro_rules! warn { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + tracing::warn!($($arg)+); + } + } +} + +macro_rules! warn_span { + ($($arg:tt)*) => { + #[cfg(feature = "tracing")] + { + let span = tracing::warn_span!($($arg)+); + let _ = span.enter(); + } + } +}