Skip to content

Commit

Permalink
log: fix LogTracer not honoring max level filters (#1543)
Browse files Browse the repository at this point in the history
Co-authored-by: Eliza Weisman <[email protected]>
  • Loading branch information
Millione and hawkw authored Sep 11, 2021
1 parent 8f80a39 commit 5fdbcbf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion tracing-log/src/log_tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ impl log::Log for LogTracer {
}

fn log(&self, record: &log::Record<'_>) {
crate::dispatch_record(record);
if self.enabled(record.metadata()) {
crate::dispatch_record(record);
}
}

fn flush(&self) {}
Expand Down
8 changes: 7 additions & 1 deletion tracing-log/tests/log_tracer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};
use tracing::collect::with_default;
use tracing_core::span::{Attributes, Record};
use tracing_core::{span, Collect, Event, Level, Metadata};
use tracing_core::{span, Collect, Event, Level, LevelFilter, Metadata};
use tracing_log::{LogTracer, NormalizeEvent};

struct State {
Expand All @@ -26,6 +26,10 @@ impl Collect for TestSubscriber {
true
}

fn max_level_hint(&self) -> Option<LevelFilter> {
Some(LevelFilter::from_level(Level::INFO))
}

fn new_span(&self, _span: &Attributes<'_>) -> span::Id {
span::Id::from_u64(42)
}
Expand Down Expand Up @@ -67,6 +71,8 @@ fn normalized_metadata() {
let state = me.clone();

with_default(TestSubscriber(me), || {
log::info!("expected info log");
log::debug!("unexpected debug log");
let log = log::Record::builder()
.args(format_args!("Error!"))
.level(log::Level::Info)
Expand Down

0 comments on commit 5fdbcbf

Please sign in to comment.