mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-09-30 14:30:42 +00:00
log: compare log
record Level
s against the max level (#1247)
This branch adds a check against the current value of the max global `LevelFilter` hint in `tracing_log`'s `LogTracer::enabled` method. This should prevent `log::${LEVEL}_enabled!` from always returning `true` when `tracing` is in use, fixing a performance issue when consuming `log` records from tracing (see bytecodealliance/wasmtime#2662). This does, however, mean `LogTracer::enabled` will always be called if the max `log` level is not set. We can't determine whether we can set `log`'s max level in `tracing_log`, since we don't know if subscribers will change (resulting in the current max `tracing` level filter changing), or if the current subscriber is set as the global default. Higher-level code in `tracing_subscriber` can do this, though, in `init()`, because it _does_ know that it's setting a global default. I'll add that in a follow-up PR. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
parent
d173c2de9a
commit
2a9d17f73f
@ -368,6 +368,7 @@ impl crate::sealed::Sealed for log::Level {}
|
||||
|
||||
impl AsTrace for log::Level {
|
||||
type Trace = tracing_core::Level;
|
||||
#[inline]
|
||||
fn as_trace(&self) -> tracing_core::Level {
|
||||
match self {
|
||||
log::Level::Error => tracing_core::Level::ERROR,
|
||||
|
@ -160,7 +160,17 @@ impl Default for LogTracer {
|
||||
|
||||
impl log::Log for LogTracer {
|
||||
fn enabled(&self, metadata: &log::Metadata<'_>) -> bool {
|
||||
// First, check the log record against the current max level enabled by
|
||||
// the current `tracing` subscriber.
|
||||
if metadata.level().as_trace() > tracing_core::LevelFilter::current() {
|
||||
// If the log record's level is above that, disable it.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Okay, it wasn't disabled by the max level — do we have any specific
|
||||
// modules to ignore?
|
||||
if self.ignore_crates.is_empty() {
|
||||
// If we don't, just enable it.
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user