log: fix LogTracer not honoring max level filters (#1543)

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
LIU JIE 2021-09-11 08:56:03 +08:00 committed by Eliza Weisman
parent a1d1282086
commit 0ab63ef5cb
2 changed files with 10 additions and 2 deletions

View File

@ -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) {}

View File

@ -1,7 +1,7 @@
use std::sync::{Arc, Mutex};
use tracing::subscriber::with_default;
use tracing_core::span::{Attributes, Record};
use tracing_core::{span, Event, Level, Metadata, Subscriber};
use tracing_core::{span, Event, Level, LevelFilter, Metadata, Subscriber};
use tracing_log::{LogTracer, NormalizeEvent};
struct State {
@ -26,6 +26,10 @@ impl Subscriber 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)
}
@ -63,6 +67,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)