🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

tracing_macros/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#[doc(hidden)]
pub use tracing;

/// Alias of `dbg!` for avoiding conflicts with the `std::dbg!` macro.
#[macro_export]
macro_rules! trace_dbg {
    (target: $target:expr, level: $level:expr, $ex:expr) => {
        $crate::dbg!(target: $target, level: $level, $ex)
    };
    (level: $level:expr, $ex:expr) => {
        $crate::dbg!(target: module_path!(), level: $level, $ex)
    };
    (target: $target:expr, $ex:expr) => {
        $crate::dbg!(target: $target, level: $crate::tracing::Level::DEBUG, $ex)
    };
    ($ex:expr) => {
        $crate::dbg!(level: $crate::tracing::Level::DEBUG, $ex)
    };
}

/// Similar to the `std::dbg!` macro, but generates `tracing` events rather
/// than printing to stdout.
///
/// By default, the verbosity level for the generated events is `DEBUG`, but
/// this can be customized.
#[macro_export]
macro_rules! dbg {
    (target: $target:expr, level: $level:expr, $ex:expr) => {{
        match $ex {
            value => {
                $crate::tracing::event!(target: $target, $level, ?value, stringify!($ex));
                value
            }
        }
    }};
    (level: $level:expr, $ex:expr) => {
        $crate::dbg!(target: module_path!(), level: $level, $ex)
    };
    (target: $target:expr, $ex:expr) => {
        $crate::dbg!(target: $target, level: $crate::tracing::Level::DEBUG, $ex)
    };
    ($ex:expr) => {
        $crate::dbg!(level: $crate::tracing::Level::DEBUG, $ex)
    };
}