Skip to main content

gpui_navigator/
logging.rs

1//! Logging abstraction layer.
2//!
3//! Provides macros that dispatch to either the [`log`](https://docs.rs/log)
4//! or [`tracing`](https://docs.rs/tracing) crate depending on which feature
5//! is enabled. The two features are **mutually exclusive** — enable at most one.
6//!
7//! | Feature    | Backend         | Default |
8//! |------------|-----------------|---------|
9//! | `log`      | `log` crate     | yes     |
10//! | `tracing`  | `tracing` crate | no      |
11//!
12//! # Available macros
13//!
14//! - `trace_log!` — finest-grained diagnostic output.
15//! - `debug_log!` — information useful for debugging.
16//! - `info_log!` — general informational messages.
17//! - `warn_log!` — potentially harmful situations.
18//! - `error_log!` — error events that might still allow the app to continue.
19//!
20//! All macros accept `format!`-style arguments:
21//!
22//! ```ignore
23//! use gpui_navigator::{trace_log, debug_log, info_log, warn_log, error_log};
24//!
25//! trace_log!("Entering resolve for path '{}'", path);
26//! debug_log!("Navigating to route: {}", path);
27//! info_log!("Navigation complete");
28//! warn_log!("Guard returned unexpected value");
29//! error_log!("Failed to resolve route: {}", err);
30//! ```
31
32/// Emit a **trace**-level log message.
33///
34/// Dispatches to `log::trace!` or `tracing::trace!` depending on the
35/// enabled feature flag. Accepts `format!`-style arguments.
36#[macro_export]
37macro_rules! trace_log {
38    ($($arg:tt)*) => {
39        #[cfg(feature = "tracing")]
40        ::tracing::trace!($($arg)*);
41        #[cfg(feature = "log")]
42        ::log::trace!($($arg)*);
43    };
44}
45
46/// Emit a **debug**-level log message.
47///
48/// Dispatches to `log::debug!` or `tracing::debug!` depending on the
49/// enabled feature flag. Accepts `format!`-style arguments.
50#[macro_export]
51macro_rules! debug_log {
52    ($($arg:tt)*) => {
53        #[cfg(feature = "tracing")]
54        ::tracing::debug!($($arg)*);
55        #[cfg(feature = "log")]
56        ::log::debug!($($arg)*);
57    };
58}
59
60/// Emit an **info**-level log message.
61///
62/// Dispatches to `log::info!` or `tracing::info!` depending on the
63/// enabled feature flag. Accepts `format!`-style arguments.
64#[macro_export]
65macro_rules! info_log {
66    ($($arg:tt)*) => {
67        #[cfg(feature = "tracing")]
68        ::tracing::info!($($arg)*);
69        #[cfg(feature = "log")]
70        ::log::info!($($arg)*);
71    };
72}
73
74/// Emit a **warn**-level log message.
75///
76/// Dispatches to `log::warn!` or `tracing::warn!` depending on the
77/// enabled feature flag. Accepts `format!`-style arguments.
78#[macro_export]
79macro_rules! warn_log {
80    ($($arg:tt)*) => {
81        #[cfg(feature = "tracing")]
82        ::tracing::warn!($($arg)*);
83        #[cfg(feature = "log")]
84        ::log::warn!($($arg)*);
85    };
86}
87
88/// Emit an **error**-level log message.
89///
90/// Dispatches to `log::error!` or `tracing::error!` depending on the
91/// enabled feature flag. Accepts `format!`-style arguments.
92#[macro_export]
93macro_rules! error_log {
94    ($($arg:tt)*) => {
95        #[cfg(feature = "tracing")]
96        ::tracing::error!($($arg)*);
97        #[cfg(feature = "log")]
98        ::log::error!($($arg)*);
99    };
100}