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