Skip to content

Commit

Permalink
subscriber: fix FmtCollector not forwarding max level (#1251)
Browse files Browse the repository at this point in the history
The `FmtCollector` type is missing a `Collect::max_level_hint
method that forwards the inner stack's max level hint.

This fixes that, and adds tests.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
  • Loading branch information
hawkw committed Feb 19, 2021
1 parent d173c2d commit f4381b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ where
self.inner.try_close(id)
}

#[inline]
fn max_level_hint(&self) -> Option<tracing_core::LevelFilter> {
self.inner.max_level_hint()
}

unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
if id == TypeId::of::<Self>() {
Some(self as *const Self as *const ())
Expand Down
9 changes: 9 additions & 0 deletions tracing-subscriber/tests/fmt_max_level_hint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use tracing_subscriber::filter::LevelFilter;

#[test]
fn fmt_sets_max_level_hint() {
tracing_subscriber::fmt()
.with_max_level(LevelFilter::DEBUG)
.init();
assert_eq!(LevelFilter::current(), LevelFilter::DEBUG);
}
10 changes: 10 additions & 0 deletions tracing-subscriber/tests/registry_max_level_hint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use tracing_subscriber::{filter::LevelFilter, prelude::*};

#[test]
fn registry_sets_max_level_hint() {
tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(LevelFilter::DEBUG)
.init();
assert_eq!(LevelFilter::current(), LevelFilter::DEBUG);
}

0 comments on commit f4381b9

Please sign in to comment.