summaryrefslogtreecommitdiffstats
path: root/third_party/rust/jsparagus-json-log/src/lib.rs
blob: ed818566e53e24beb95d6bb5139dac2954ec3a11 (plain)
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
//! Provides a debug/trace output with json format.
//! This is disabled by default, and can be enabled by "logging" feature.

#[cfg(feature = "logging")]
pub use log::{debug, trace};
#[cfg(feature = "logging")]
pub use serde_json::json;

#[cfg(not(feature = "logging"))]
#[macro_export]
macro_rules! json_debug {
    ($($t:tt)*) => {};
}

#[cfg(feature = "logging")]
#[macro_export(local_inner_macros)]
macro_rules! json_debug {
    ($($t:tt)*) => {
        debug!(
            "{}",
            json!($($t)*)
        );
    };
}

#[cfg(not(feature = "logging"))]
#[macro_export]
macro_rules! json_trace {
    ($($t:tt)*) => {};
}

#[cfg(feature = "logging")]
#[macro_export(local_inner_macros)]
macro_rules! json_trace {
    ($($t:tt)*) => {
        trace!(
            "{}",
            json!($($t)*)
        );
    };
}