|
| 1 | +// Copyright (c) 2025 Contributors to the Eclipse Foundation |
| 2 | +// |
| 3 | +// See the NOTICE file(s) distributed with this work for additional |
| 4 | +// information regarding copyright ownership. |
| 5 | +// |
| 6 | +// This program and the accompanying materials are made available under the |
| 7 | +// terms of the Apache License Version 2.0 which is available at |
| 8 | +// <https://www.apache.org/licenses/LICENSE-2.0> |
| 9 | +// |
| 10 | +// SPDX-License-Identifier: Apache-2.0 |
| 11 | + |
| 12 | +//! Logging module. |
| 13 | +//! Utilizes `"PERS"` context by default. |
| 14 | +
|
| 15 | +#![allow(unused_macros)] |
| 16 | + |
| 17 | +pub(crate) const CONTEXT: &str = "PERS"; |
| 18 | + |
| 19 | +/// Proxy for `mw_log::fatal!`. |
| 20 | +#[clippy::format_args] |
| 21 | +macro_rules! fatal { |
| 22 | + // fatal!(logger: my_logger, "a {} event", "log") |
| 23 | + (logger: $logger:expr, $($arg:tt)+) => (mw_log::fatal!(logger: $logger, context: $crate::log::CONTEXT, $($arg)+)); |
| 24 | + |
| 25 | + // fatal!("a {} event", "log") |
| 26 | + ($($arg:tt)+) => (mw_log::fatal!(context: $crate::log::CONTEXT, $($arg)+)); |
| 27 | +} |
| 28 | + |
| 29 | +/// Proxy for `mw_log::error!`. |
| 30 | +#[clippy::format_args] |
| 31 | +macro_rules! error { |
| 32 | + // error!(logger: my_logger, "a {} event", "log") |
| 33 | + (logger: $logger:expr, $($arg:tt)+) => (mw_log::error!(logger: $logger, context: $crate::log::CONTEXT, $($arg)+)); |
| 34 | + |
| 35 | + // error!("a {} event", "log") |
| 36 | + ($($arg:tt)+) => (mw_log::error!(context: $crate::log::CONTEXT, $($arg)+)); |
| 37 | +} |
| 38 | + |
| 39 | +/// Proxy for `mw_log::warn!`. |
| 40 | +#[clippy::format_args] |
| 41 | +macro_rules! warning { |
| 42 | + // warn!(logger: my_logger, "a {} event", "log") |
| 43 | + (logger: $logger:expr, $($arg:tt)+) => (mw_log::warn!(logger: $logger, context: $crate::log::CONTEXT, $($arg)+)); |
| 44 | + |
| 45 | + // warn!("a {} event", "log") |
| 46 | + ($($arg:tt)+) => (mw_log::warn!(context: $crate::log::CONTEXT, $($arg)+)); |
| 47 | +} |
| 48 | + |
| 49 | +/// Proxy for `mw_log::info!`. |
| 50 | +#[clippy::format_args] |
| 51 | +macro_rules! info { |
| 52 | + // info!(logger: my_logger, "a {} event", "log") |
| 53 | + (logger: $logger:expr, $($arg:tt)+) => (mw_log::info!(logger: $logger, context: $crate::log::CONTEXT, $($arg)+)); |
| 54 | + |
| 55 | + // info!("a {} event", "log") |
| 56 | + ($($arg:tt)+) => (mw_log::info!(context: $crate::log::CONTEXT, $($arg)+)); |
| 57 | +} |
| 58 | + |
| 59 | +/// Proxy for `mw_log::debug!`. |
| 60 | +#[clippy::format_args] |
| 61 | +macro_rules! debug { |
| 62 | + // debug!(logger: my_logger, "a {} event", "log") |
| 63 | + (logger: $logger:expr, $($arg:tt)+) => (mw_log::debug!(logger: $logger, context: $crate::log::CONTEXT, $($arg)+)); |
| 64 | + |
| 65 | + // debug!("a {} event", "log") |
| 66 | + ($($arg:tt)+) => (mw_log::debug!(context: $crate::log::CONTEXT, $($arg)+)); |
| 67 | +} |
| 68 | + |
| 69 | +/// Proxy for `mw_log::trace!`. |
| 70 | +#[clippy::format_args] |
| 71 | +macro_rules! trace { |
| 72 | + // trace!(logger: my_logger, "a {} event", "log") |
| 73 | + (logger: $logger:expr, $($arg:tt)+) => (mw_log::trace!(logger: $logger, context: $crate::log::CONTEXT, $($arg)+)); |
| 74 | + |
| 75 | + // trace!("a {} event", "log") |
| 76 | + ($($arg:tt)+) => (mw_log::trace!(context: $crate::log::CONTEXT, $($arg)+)); |
| 77 | +} |
| 78 | + |
| 79 | +// Export macros from this module (e.g., `crate::log::error`). |
| 80 | +// `#[macro_export]` would export them from crate (e.g., `crate::error`). |
| 81 | +// |
| 82 | +// `warning as warn` is due to `warn` macro name conflicting with `warn` attribute. |
| 83 | +#[allow(unused_imports)] |
| 84 | +pub(crate) use {debug, error, fatal, info, trace, warning as warn}; |
| 85 | + |
| 86 | +// Re-export symbols from `mw_log`. |
| 87 | +pub(crate) use mw_log::fmt::ScoreDebug; |
| 88 | +pub(crate) use mw_log::ScoreDebug; |
0 commit comments