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

feat(subscriber): use per-layer filtering #140

Merged
merged 1 commit into from
Sep 13, 2021
Merged

feat(subscriber): use per-layer filtering #140

merged 1 commit into from
Sep 13, 2021

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Sep 13, 2021

Currently, the console_subscriber::build() and
console_subscriber::init() functions configure an EnvFilter that
enables the tokio and runtime targets, plus any targets configured
by RUST_LOG. This means that the tokio spans used by the console
will always be enabled at the TRACE level for all layers. This
includes the fmt layer we previously added in init.

Since this resulted in the fmt layer logs being cluttered with a bunch
of tokio=trace spans and events even when only high-level application
logs are enabled by RUST_LOG, we removed the fmt 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. We
can now use the per-layer filtering API to selectively enable the
tokio/runtime spans and events at the TRACE level only for the
TasksLayer, and add a filter to the fmt layer based on RUST_LOG.
This allows us to put back the fmt layer in
console_subscriber::init.

Now, if we run the example app (which uses init) with a RUST_LOG
value that enables only the app's logs, we get nice output:

image

However, we can also enable the console-subscriber crate's internal
logging:

image

And, we can still enable tokio=trace ourselves, if we actually want
to see all the task spans and waker events:

image

I also added some trace! and debug! macros in examples/app.rs to
demo that console_subscriber::init() also enables logging.

Closes #76

@hawkw hawkw self-assigned this Sep 13, 2021
@hawkw hawkw added C-subscriber Crate: console-subscriber. S-feature Severity: feature. This is adding a new feature. labels Sep 13, 2021
Currently, the `console_subscriber::build()` and
`console_subscriber::init()` functions configure an `EnvFilter` that
enables the `tokio` and `runtime` targets, plus any targets configured
by `RUST_LOG`. This means that the `tokio` spans used by the console
will always be enabled at the `TRACE` level for all layers. This
includes the `fmt` layer we previously added in `init`.

Since this resulted in the `fmt` layer logs being cluttered with a bunch
of `tokio=trace` spans and events even when only high-level application
logs are enabled by `RUST_LOG`, we removed the `fmt` 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`. We
can now use the per-layer filtering API to selectively enable the
`tokio`/`runtime` spans and events at the `TRACE` level _only_ for the
`TasksLayer`, and add a filter to the `fmt` layer based on `RUST_LOG`.
This allows us to put back the `fmt` layer in
`console_subscriber::init`.

Closes #76
Copy link
Member

@seanmonstar seanmonstar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@hawkw hawkw merged commit f2c30d5 into main Sep 13, 2021
@hawkw hawkw deleted the eliza/plf branch September 13, 2021 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-subscriber Crate: console-subscriber. S-feature Severity: feature. This is adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need some way to enable "tokio=trace" filter for the console Layer only
2 participants