Skip to content

log: compare log record Levels against the max level #1247

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

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tracing-log/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,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,
Expand Down
10 changes: 10 additions & 0 deletions tracing-log/src/log_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,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;
}

Expand Down