-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: fix
max_level_hint
for empty Option
/Vec
Subscribe
…
… impls (#2195) ## Motivation These are incorrect: currently, when you have a `None` layer, the `None` hint it returns causes the default `TRACE` to win, which is inaccurate. Similarly, `Vec` should default to `OFF` if it has no `Subscribe`s in it ## Solution Change the default hints to `Some(OFF)` Co-authored-by: Eliza Weisman <eliza@buoyant.io>
- Loading branch information
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#![cfg(feature = "registry")] | ||
use tracing::level_filters::LevelFilter; | ||
use tracing::Collect; | ||
use tracing_subscriber::prelude::*; | ||
|
||
// This test is just used to compare to the tests below | ||
#[test] | ||
fn just_subscriber() { | ||
let collector = tracing_subscriber::registry().with(LevelFilter::INFO); | ||
assert_eq!(collector.max_level_hint(), Some(LevelFilter::INFO)); | ||
} | ||
|
||
#[test] | ||
fn subscriber_and_option_some_subscriber() { | ||
let collector = tracing_subscriber::registry() | ||
.with(LevelFilter::INFO) | ||
.with(Some(LevelFilter::DEBUG)); | ||
assert_eq!(collector.max_level_hint(), Some(LevelFilter::DEBUG)); | ||
} | ||
|
||
#[test] | ||
fn subscriber_and_option_none_subscriber() { | ||
// None means the other layer takes control | ||
let collector = tracing_subscriber::registry() | ||
.with(LevelFilter::ERROR) | ||
.with(None::<LevelFilter>); | ||
assert_eq!(collector.max_level_hint(), Some(LevelFilter::ERROR)); | ||
} | ||
|
||
#[test] | ||
fn just_option_some_subscriber() { | ||
// Just a None means everything is off | ||
let collector = tracing_subscriber::registry().with(None::<LevelFilter>); | ||
assert_eq!(collector.max_level_hint(), Some(LevelFilter::OFF)); | ||
} | ||
|
||
#[test] | ||
fn just_option_none_subscriber() { | ||
let collector = tracing_subscriber::registry().with(Some(LevelFilter::ERROR)); | ||
assert_eq!(collector.max_level_hint(), Some(LevelFilter::ERROR)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![cfg(feature = "registry")] | ||
use tracing::level_filters::LevelFilter; | ||
use tracing::Collect; | ||
use tracing_subscriber::prelude::*; | ||
|
||
#[test] | ||
fn just_empty_vec() { | ||
// Just a None means everything is off | ||
let collector = tracing_subscriber::registry().with(Vec::<LevelFilter>::new()); | ||
assert_eq!(collector.max_level_hint(), Some(LevelFilter::OFF)); | ||
} | ||
|
||
#[test] | ||
fn subscriber_and_empty_vec() { | ||
let collector = tracing_subscriber::registry() | ||
.with(LevelFilter::INFO) | ||
.with(Vec::<LevelFilter>::new()); | ||
assert_eq!(collector.max_level_hint(), Some(LevelFilter::INFO)); | ||
} |