|
|
|
|
@@ -1,13 +1,40 @@
|
|
|
|
|
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: GNU General Public License v3.0 or later
|
|
|
|
|
|
|
|
|
|
//! Logging targets allow filtering of log messages by their source. By default, the log crate sets
|
|
|
|
|
//! the target to the module path where the log macro was invoked if no target is provided.
|
|
|
|
|
//!
|
|
|
|
|
//! These macros essentially disable using the default target and instead require the target to be
|
|
|
|
|
//! explicitly set. This is to avoid implicit pooling of log messages under the same default target,
|
|
|
|
|
//! which can make it difficult to filter log messages by their source.
|
|
|
|
|
//!
|
|
|
|
|
//! The target argument can be overridden using one of the following macros.
|
|
|
|
|
//! ```
|
|
|
|
|
//! libclide::log!(target: "CustomTarget", "This log message will have the target 'CustomTarget'");
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! The target argument will default to Self::ID if not provided.
|
|
|
|
|
//! This is an error if Self::ID is not defined, forcing you to use the explicit form.
|
|
|
|
|
//! ```
|
|
|
|
|
//! libclide::log!("This log message will use target Self::ID, the name of the struct it was invoked in");
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Self::ID can be defined using the `#[log_id]` attribute macro, which will automatically generate
|
|
|
|
|
//! a constant ID field with the name of the struct as its value.
|
|
|
|
|
//! ```
|
|
|
|
|
//! #[log_id]
|
|
|
|
|
//! struct MyStruct;
|
|
|
|
|
//! impl MyStruct {
|
|
|
|
|
//! fn my_method(&self) {
|
|
|
|
|
//! libclide::log!("This log message will use target Self::ID, which is 'MyStruct'");
|
|
|
|
|
//! }
|
|
|
|
|
//! }
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! info {
|
|
|
|
|
// The target argument can be overridden using one of the following macros.
|
|
|
|
|
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::info!(logger: $logger, target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -16,8 +43,6 @@ macro_rules! info {
|
|
|
|
|
log::info!(target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The target argument will default to Self::ID if not provided.
|
|
|
|
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
|
|
|
|
(logger: $logger:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::info!(logger: $logger, target: Self::ID, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -27,7 +52,6 @@ macro_rules! info {
|
|
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! debug {
|
|
|
|
|
// The target argument can be overridden using one of the following macros.
|
|
|
|
|
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::debug!(logger: $logger, target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -36,8 +60,6 @@ macro_rules! debug {
|
|
|
|
|
log::debug!(target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The target argument will default to Self::ID if not provided.
|
|
|
|
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
|
|
|
|
(logger: $logger:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::debug!(logger: $logger, target: Self::ID, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -47,7 +69,6 @@ macro_rules! debug {
|
|
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! warn {
|
|
|
|
|
// The target argument can be overridden using one of the following macros.
|
|
|
|
|
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::warn!(logger: $logger, target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -56,8 +77,6 @@ macro_rules! warn {
|
|
|
|
|
log::warn!(target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The target argument will default to Self::ID if not provided.
|
|
|
|
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
|
|
|
|
(logger: $logger:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::warn!(logger: $logger, target: Self::ID, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -67,7 +86,6 @@ macro_rules! warn {
|
|
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! error {
|
|
|
|
|
// The target argument can be overridden using one of the following macros.
|
|
|
|
|
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::error!(logger: $logger, target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -76,8 +94,6 @@ macro_rules! error {
|
|
|
|
|
log::error!(target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The target argument will default to Self::ID if not provided.
|
|
|
|
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
|
|
|
|
(logger: $logger:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::error!(logger: $logger, target: Self::ID, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -87,7 +103,6 @@ macro_rules! error {
|
|
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
|
macro_rules! trace {
|
|
|
|
|
// The target argument can be overridden using one of the following macros.
|
|
|
|
|
(logger: $logger:expr, target: $target:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::trace!(logger: $logger, target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
@@ -96,8 +111,6 @@ macro_rules! trace {
|
|
|
|
|
log::trace!(target: $target, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// The target argument will default to Self::ID if not provided.
|
|
|
|
|
// Obviously, this is an error if Self::ID is not defined, forcing you to use the explicit form.
|
|
|
|
|
(logger: $logger:expr, $($arg:tt)+) => ({
|
|
|
|
|
log::trace!(logger: $logger, target: Self::ID, $($arg)+)
|
|
|
|
|
});
|
|
|
|
|
|