taitan_orm_tracing/
lib.rs

1#[cfg(feature = "tracing")]
2pub use tracing::{
3    debug, error, info, trace, warn,
4    debug_span, error_span, info_span, trace_span, warn_span
5};
6
7#[cfg(not(feature = "tracing"))]
8mod noop_macros {
9    #[macro_export]
10    macro_rules! trace {
11        ($($args:tt)*) => {};
12    }
13
14    #[macro_export]
15    macro_rules! debug {
16        ($($args:tt)*) => {};
17    }
18
19    #[macro_export]
20    macro_rules! info {
21        ($($args:tt)*) => {};
22    }
23
24    #[macro_export]
25    macro_rules! warn {
26        ($($args:tt)*) => {};
27    }
28
29    #[macro_export]
30    macro_rules! error {
31        ($($args:tt)*) => {};
32    }
33
34    #[macro_export]
35    macro_rules! trace_span {
36        ($($args:tt)*) => {
37            pub struct NoopSpan;
38            impl NoopSpan {
39                #[allow(unused)]
40                pub fn enter(&self) -> NoopSpanGuard { NoopSpanGuard }
41            }
42            pub struct NoopSpanGuard;
43            impl Drop for NoopSpanGuard {
44                fn drop(&mut self) {}
45            }
46            NoopSpan
47        };
48    }
49
50    // 修正后的宏定义方式
51    #[macro_export]
52    macro_rules! debug_span {
53        ($($args:tt)*) => {
54            $crate::noop_macros::trace_span!($($args)*)
55        };
56    }
57
58    #[macro_export]
59    macro_rules! info_span {
60        ($($args:tt)*) => {
61            $crate::noop_macros::trace_span!($($args)*)
62        };
63    }
64
65    #[macro_export]
66    macro_rules! warn_span {
67        ($($args:tt)*) => {
68            $crate::noop_macros::trace_span!($($args)*)
69        };
70    }
71
72    #[macro_export]
73    macro_rules! error_span {
74        ($($args:tt)*) => {
75            $crate::noop_macros::trace_span!($($args)*)
76        };
77    }
78}
79
80#[cfg(not(feature = "tracing"))]
81pub use noop_macros::*;