Skip to main content

foxy/logging/
wrapper.rs

1// In src/logging/wrapper.rs
2
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7//! Logging wrapper macros that route all messages to the standard `log` facade.
8//! The `slog_stdlog` bridge (configured in `structured.rs`) handles forwarding
9//! to `slog` when structured logging is enabled. This unified approach is
10//! simpler and more robust.
11
12/// Macro to log an error message with context.
13#[macro_export]
14macro_rules! error_fmt {
15    ($context:expr, $($arg:tt)+) => {
16        log::error!("[{}] {}", $context, format_args!($($arg)+))
17    };
18}
19
20/// Macro to log a warning message with context.
21#[macro_export]
22macro_rules! warn_fmt {
23    ($context:expr, $($arg:tt)+) => {
24        log::warn!("[{}] {}", $context, format_args!($($arg)+))
25    };
26}
27
28/// Macro to log an info message with context.
29#[macro_export]
30macro_rules! info_fmt {
31    ($context:expr, $($arg:tt)+) => {
32        log::info!("[{}] {}", $context, format_args!($($arg)+))
33    };
34}
35
36/// Macro to log a debug message with context.
37#[macro_export]
38macro_rules! debug_fmt {
39    ($context:expr, $($arg:tt)+) => {
40        log::debug!("[{}] {}", $context, format_args!($($arg)+))
41    };
42}
43
44/// Macro to log a trace message with context.
45#[macro_export]
46macro_rules! trace_fmt {
47    ($context:expr, $($arg:tt)+) => {
48        log::trace!("[{}] {}", $context, format_args!($($arg)+))
49    };
50}
51
52/// Macro to log an error message
53#[macro_export]
54macro_rules! error {
55    ($($arg:tt)+) => {
56        log::error!($($arg)+)
57    };
58}
59
60/// Macro to log a warning message
61#[macro_export]
62macro_rules! warn {
63    ($($arg:tt)+) => {
64        log::warn!($($arg)+)
65    };
66}
67
68/// Macro to log an info message
69#[macro_export]
70macro_rules! info {
71    ($($arg:tt)+) => {
72        log::info!($($arg)+)
73    };
74}
75
76/// Macro to log a debug message
77#[macro_export]
78macro_rules! debug {
79    ($($arg:tt)+) => {
80        log::debug!($($arg)+)
81    };
82}
83
84/// Macro to log a trace message
85#[macro_export]
86macro_rules! trace {
87    ($($arg:tt)+) => {
88        log::trace!($($arg)+)
89    };
90}