-
Notifications
You must be signed in to change notification settings - Fork 741
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
Impl Layer
for Option<T:Layer>
#910
Conversation
Fixes tokio-rs#894 This PR implements Layer for Option, allowing users to wrap a Layer with an Option, allowing it to be passed internally wherever Layer is used there by allowing by allowing layers to be enabled or disabled. Using this with `reload` further allows a Layer to be dynamically toggled based by using `handle.modify` This PR also consists of a basic example. Signed-off-by: Tarun Pothulapati <[email protected]>
Signed-off-by: Tarun Pothulapati <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks like the right approach. I had some suggestions.
match self { | ||
Some(ref inner) => inner.max_level_hint(), | ||
None => None, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, take it or leave it: this could also be expressed using Option::and_then
, like this:
match self { | |
Some(ref inner) => inner.max_level_hint(), | |
None => None, | |
} | |
self.and_then(Layer::max_level_hint) |
let (json, plain) = if matches.is_present("json") { | ||
(Some(tracing_subscriber::fmt::layer().json()), None) | ||
} else { | ||
(None, Some(tracing_subscriber::fmt::layer())) | ||
}; | ||
|
||
tracing_subscriber::registry().with(json).with(plain).init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have an abbreviated version of this example in the docs for the Layer
trait. Maybe also a version showing runtime reloading in the layer::reload
docs.
Signed-off-by: Tarun Pothulapati <[email protected]>
Signed-off-by: Tarun Pothulapati <[email protected]>
Signed-off-by: Tarun Pothulapati <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, this looks good to me, although I had a couple of non-blocking suggestions.
It might also be nice to have a variant of some of the benchmarks to measure how much overhead is introduced by skipping a None
layer, but I'm not going to block merging on that either.
And, I'd still like to see examples in the API docs for Layer
and for reload
to demonstrate the use of Option
layers. But, that can also be added later if necessary.
@hawkw I was planning to update this PR to show a layered reload example, along with the benchmarking suggestion over the weekend. Sorry! I will try to open another PR on the same! :) |
Fixed - **env-filter**: Fixed a regression where `Option<Level>` lost its `Into<LevelFilter>` impl ([#966]) - **env-filter**: Fixed `EnvFilter` enabling spans that should not be enabled when multiple subscribers are in use ([#927]) Changed - **json**: `format::Json` now outputs fields in a more readable order ([#892]) - Updated `tracing-core` dependency to 0.1.16 Added - **fmt**: Add `BoxMakeWriter` for erasing the type of a `MakeWriter` implementation ([#958]) - **fmt**: Add `TestWriter` `MakeWriter` implementation to support libtest output capturing ([#938]) - **layer**: Add `Layer` impl for `Option<T> where T: Layer` ([#910]) - **env-filter**: Add `From<Level>` impl for `Directive` ([#918]) - Multiple documentation fixes and improvements Thanks to @Pothulapati, @samrg472, @bryanburgers, @keetonian, and @SriRamanujam for contributing to this release! [#927]: #927 [#966]: #966 [#958]: #958 [#892]: #892 [#938]: #938 [#910]: #910 [#918]: #918
# 0.2.12 (September 8, 2020) ### Fixed - **env-filter**: Fixed a regression where `Option<Level>` lost its `Into<LevelFilter>` impl ([#966]) - **env-filter**: Fixed `EnvFilter` enabling spans that should not be enabled when multiple subscribers are in use ([#927]) ### Changed - **json**: `format::Json` now outputs fields in a more readable order ([#892]) - Updated `tracing-core` dependency to 0.1.16 ### Added - **fmt**: Add `BoxMakeWriter` for erasing the type of a `MakeWriter` implementation ([#958]) - **fmt**: Add `TestWriter` `MakeWriter` implementation to support libtest output capturing ([#938]) - **layer**: Add `Layer` impl for `Option<T> where T: Layer` ([#910]) - **env-filter**: Add `From<Level>` impl for `Directive` ([#918]) - Multiple documentation fixes and improvements Thanks to @Pothulapati, @samrg472, @bryanburgers, @keetonian, and @SriRamanujam for contributing to this release! [#927]: #927 [#966]: #966 [#958]: #958 [#892]: #892 [#938]: #938 [#910]: #910 [#918]: #918
Motivation
Fixes #894
Solution
This PR implements Layer for Option, allowing users to wrap a Layer with
an Option, allowing it to be passed internally wherever Layer is used
there by allowing by allowing layers to be enabled or disabled.
Using this with
reload
further allows a Layer to be dynamicallytoggled based by using
handle.modify
This PR also consists of a basic example.
Signed-off-by: Tarun Pothulapati [email protected]