lib.rs

 1pub use tracing::{Level, field};
 2
 3#[cfg(ztracing)]
 4pub use tracing::{
 5    Span, debug_span, error_span, event, info_span, instrument, span, trace_span, warn_span,
 6};
 7#[cfg(not(ztracing))]
 8pub use ztracing_macro::instrument;
 9
10#[cfg(all(ztracing, ztracing_with_memory))]
11#[global_allocator]
12static GLOBAL: tracy_client::ProfiledAllocator<std::alloc::System> =
13    tracy_client::ProfiledAllocator::new(std::alloc::System, 100);
14
15#[cfg(not(ztracing))]
16pub use __consume_all_tokens as trace_span;
17#[cfg(not(ztracing))]
18pub use __consume_all_tokens as info_span;
19#[cfg(not(ztracing))]
20pub use __consume_all_tokens as debug_span;
21#[cfg(not(ztracing))]
22pub use __consume_all_tokens as warn_span;
23#[cfg(not(ztracing))]
24pub use __consume_all_tokens as error_span;
25#[cfg(not(ztracing))]
26pub use __consume_all_tokens as event;
27#[cfg(not(ztracing))]
28pub use __consume_all_tokens as span;
29
30#[cfg(not(ztracing))]
31#[macro_export]
32macro_rules! __consume_all_tokens {
33    ($($t:tt)*) => {
34        $crate::Span
35    };
36}
37
38#[cfg(not(ztracing))]
39pub struct Span;
40
41#[cfg(not(ztracing))]
42impl Span {
43    pub fn current() -> Self {
44        Self
45    }
46
47    pub fn enter(&self) {}
48
49    pub fn record<T, S>(&self, _t: T, _s: S) {}
50}
51
52#[cfg(ztracing)]
53pub fn init() {
54    use tracing_subscriber::fmt::format::DefaultFields;
55    use tracing_subscriber::prelude::*;
56
57    #[derive(Default)]
58    struct TracyLayerConfig {
59        fmt: DefaultFields,
60    }
61
62    impl tracing_tracy::Config for TracyLayerConfig {
63        type Formatter = DefaultFields;
64
65        fn formatter(&self) -> &Self::Formatter {
66            &self.fmt
67        }
68
69        fn stack_depth(&self, _: &tracing::Metadata) -> u16 {
70            8
71        }
72
73        fn format_fields_in_zone_name(&self) -> bool {
74            true
75        }
76
77        fn on_error(&self, client: &tracy_client::Client, error: &'static str) {
78            client.color_message(error, 0xFF000000, 0);
79        }
80    }
81
82    zlog::info!("Starting tracy subscriber, you can now connect the profiler");
83    tracing::subscriber::set_global_default(
84        tracing_subscriber::registry()
85            .with(tracing_tracy::TracyLayer::new(TracyLayerConfig::default())),
86    )
87    .expect("setup tracy layer");
88}
89
90#[cfg(not(ztracing))]
91pub fn init() {}