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// The following simple wrapper macros and functions are no longer necessary
53// with this unified approach, as standard `log::*` macros can be used directly.
54// You may want to remove them from here and `src/logging/mod.rs` to clean up the code.
55
56/// Macro to log an error message
57#[macro_export]
58macro_rules! error {
59 ($($arg:tt)+) => {
60 log::error!($($arg)+)
61 };
62}
63
64/// Macro to log a warning message
65#[macro_export]
66macro_rules! warn {
67 ($($arg:tt)+) => {
68 log::warn!($($arg)+)
69 };
70}
71
72/// Macro to log an info message
73#[macro_export]
74macro_rules! info {
75 ($($arg:tt)+) => {
76 log::info!($($arg)+)
77 };
78}
79
80/// Macro to log a debug message
81#[macro_export]
82macro_rules! debug {
83 ($($arg:tt)+) => {
84 log::debug!($($arg)+)
85 };
86}
87
88/// Macro to log a trace message
89#[macro_export]
90macro_rules! trace {
91 ($($arg:tt)+) => {
92 log::trace!($($arg)+)
93 };
94}