feat(subscriber): use per-layer filtering #140
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the
console_subscriber::build()
andconsole_subscriber::init()
functions configure anEnvFilter
thatenables the
tokio
andruntime
targets, plus any targets configuredby
RUST_LOG
. This means that thetokio
spans used by the consolewill always be enabled at the
TRACE
level for all layers. Thisincludes the
fmt
layer we previously added ininit
.Since this resulted in the
fmt
layer logs being cluttered with a bunchof
tokio=trace
spans and events even when only high-level applicationlogs are enabled by
RUST_LOG
, we removed thefmt
layer in PR #64.However, tokio-rs/tracing#1523 was recently merged and [released][1],
adding support for [per-layer filtering][2] to
tracing-subscriber
. Wecan now use the per-layer filtering API to selectively enable the
tokio
/runtime
spans and events at theTRACE
level only for theTasksLayer
, and add a filter to thefmt
layer based onRUST_LOG
.This allows us to put back the
fmt
layer inconsole_subscriber::init
.Now, if we run the example app (which uses
init
) with aRUST_LOG
value that enables only the app's logs, we get nice output:
However, we can also enable the
console-subscriber
crate's internallogging:
And, we can still enable
tokio=trace
ourselves, if we actually wantto see all the task spans and waker events:
I also added some
trace!
anddebug!
macros inexamples/app.rs
todemo that
console_subscriber::init()
also enables logging.Closes #76