Skip to content
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

fix: log level filter with trace #1543

Merged
merged 2 commits into from
Sep 11, 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
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