-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: meta logging in logger? #645
Comments
This is a tricky topic, and one that any log framework will encounter at some point. Since |
@KodrAus I'm considering a related topic: whether it's reasonable to add an optional The idea comes from spdlog-rs (cc @SpriteOvO) where they have: /// # Examples
///
/// ```
/// use spdlog::debug;
///
/// # struct Position { x: f32, y: f32 }
/// # let app_events = spdlog::default_logger();
/// let pos = Position { x: 3.234, y: -1.223 };
///
/// // Using the global default logger
/// debug!("New position: x: {}, y: {}", pos.x, pos.y);
///
/// // Or using the specified logger
/// debug!(logger: app_events, "New position: x: {}, y: {}", pos.x, pos.y);
/// ```
#[macro_export]
macro_rules! debug {
(logger: $logger:expr, $($arg:tt)+) => (
$crate::log!(logger: $logger, $crate::Level::Debug, $($arg)+)
);
($($arg:tt)+) => (
$crate::log!($crate::Level::Debug, $($arg)+)
)
} and "Named optional parameters"
|
This can possibly work around the meta logging issue because one can configure different logger for different use case, the same as log4j can apply different config for different logger (https://logging.apache.org/log4j/2.x/manual/configuration.html#logger-attributes-name) |
Adding a logger parameter to the macros would be a worthwhile enhancement I think 👍 |
Some
log
implementations support logger pipeline. For example, inlogforth
you can write:When I'm trying to add some complex appenders, for example, Kafka appender, it's natural to use a Kafka client lib. However, such a client lib may log inside also, which can result in an infinite recursive logging if such an appender is installed globally.
I did some investigation and how a possible solution, but would like to open this issue for discussion:
This is, however, both brittle and may filter logs from user code. I don't know how targets are defined and if we can reliably depend on that matches.
The text was updated successfully, but these errors were encountered: