-
Notifications
You must be signed in to change notification settings - Fork 734
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
subscriber: warn if trying to enable a statically disabled level #990
Conversation
8cb716b
to
b745d09
Compare
I'm not sure how to add tests for this ... the existing tests in |
cca54b5
to
e1e58cb
Compare
Originally this added a |
@@ -24,7 +24,7 @@ keywords = ["logging", "tracing", "metrics", "subscriber"] | |||
[features] | |||
|
|||
default = ["env-filter", "smallvec", "fmt", "ansi", "chrono", "tracing-log", "json"] | |||
env-filter = ["matchers", "regex", "lazy_static"] | |||
env-filter = ["matchers", "regex", "lazy_static", "tracing"] |
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.
Not sure tracing
needs to be another feature flag on this. I don't see this flag being used elsewhere and I think that a tracing dependency is a forgone conclusion for tracing-subscriber
.
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.
This won't compile without adding a tracing
dependency:
error[E0433]: failed to resolve: use of undeclared type or module `tracing`
--> tracing-subscriber/src/filter/env/mod.rs:245:13
|
245 | use tracing::level_filters::STATIC_MAX_LEVEL;
| ^^^^^^^ use of undeclared type or module `tracing`
error[E0433]: failed to resolve: use of undeclared type or module `tracing`
--> tracing-subscriber/src/filter/env/mod.rs:245:13
|
245 | use tracing::level_filters::STATIC_MAX_LEVEL;
| ^^^^^^^ use of undeclared type or module `tracing`
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.
I'd like to hear what @hawkw says, but I'm not sure tracing
merits being an optional dependency.
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.
Oh I see, you want to make it always a dependency instead of optional. Sure, I can do that.
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.
I think the tracing
dependency should be optional and only enabled by the "env-filter" feature. Otherwise, there's no reason to depend on tracing
--- the rest of the crate only uses tracing-core
.
I think @davidbarsky misinterpreted this change as adding a new feature flag "tracing" that users could independently enable. That's not what this change is doing --- it simply makes the "env-filter" feature enable a dependency on tracing
that isn't otherwise necessary.
IMO the original code was correct.
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.
Ok, I reverted it to the original code.
@@ -24,7 +24,7 @@ keywords = ["logging", "tracing", "metrics", "subscriber"] | |||
[features] | |||
|
|||
default = ["env-filter", "smallvec", "fmt", "ansi", "chrono", "tracing-log", "json"] | |||
env-filter = ["matchers", "regex", "lazy_static"] | |||
env-filter = ["matchers", "regex", "lazy_static", "tracing"] |
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.
I'd like to hear what @hawkw says, but I'm not sure tracing
merits being an optional dependency.
This implements the warning in `tracing-subscriber` only, as mentioned in tokio-rs#975 (comment). It warns whenever directives are parsed, including programmatically and through environment variables. It does not include the suggested new API which returns the filters that wouldn't be parsed. - List filters that would be ignored - Mention 'static max level' - Describe how to enable the logging Example output: ``` $ RUST_LOG=off,debug,silenced[x]=trace cargo run -q warning: some trace filter directives would enable traces that are disabled statically | `debug` would enable the DEBUG level for all targets | `silenced[x]=trace` would enable the TRACE level for the `silenced` target | the static max level is info note: to enable DEBUG logging, remove the `max_level_info` feature ``` Fixes: tokio-rs#975
Co-authored-by: David Barsky <me@davidbarsky.com>
- Make `tracing` mandatory - Group crate-public fields together
Rebased over master to get the test fix from #1016. |
eprintln!("warning: some trace filter directives would enable traces that are disabled statically"); | ||
for directive in disabled { | ||
let target = if let Some(target) = &directive.target { | ||
format!("the `{}` target", target) | ||
} else { | ||
"all targets".into() | ||
}; | ||
let level = directive | ||
.level | ||
.clone() | ||
.into_level() | ||
.expect("=off would not have enabled any filters"); | ||
eprintln!( | ||
" | `{}` would enable the {} level for {}", | ||
directive, level, target | ||
); | ||
} | ||
eprintln!(" | the static max level is {}", STATIC_MAX_LEVEL); | ||
let help_msg = || { | ||
let (feature, filter) = match STATIC_MAX_LEVEL.into_level() { | ||
Some(Level::TRACE) => unreachable!( | ||
"if the max level is trace, no static filtering features are enabled" | ||
), | ||
Some(Level::DEBUG) => ("max_level_debug", Level::TRACE), | ||
Some(Level::INFO) => ("max_level_info", Level::DEBUG), | ||
Some(Level::WARN) => ("max_level_warn", Level::INFO), | ||
Some(Level::ERROR) => ("max_level_error", Level::WARN), | ||
None => return ("max_level_off", String::new()), | ||
}; | ||
(feature, format!("{} ", filter)) | ||
}; | ||
let (feature, earlier_level) = help_msg(); | ||
eprintln!( | ||
"note: to enable {}logging, remove the `{}` feature", | ||
earlier_level, feature | ||
); |
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.
FWIW, when I suggested output like
$ RUST_LOG=off,debug,silenced[x]=trace cargo run -q warning: some trace filter directives would enable traces that are disabled statically | `debug` would enable the DEBUG level for all targets | `silenced[x]=trace` would enable the TRACE level for the `silenced` target | the static max level is info note: to enable DEBUG logging, remove the `max_level_info` feature
i was trying to imitate the formatting used by rustc
's error messages, since I know this feature was originally requested for rustc.
Since we already have the "ansi" feature flag for enabling colored terminal output via the ansi_term
crate, we might want to try using the same colors and other formatting that the compiler uses, when that feature is enabled?
It would be fine to make this change in a follow up PR, rather than block merging this one --- it's just a thought.
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.
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.
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.
i was trying to imitate the formatting used by rustc's error messages, since I know this feature was originally requested for rustc.
I should probably work on colorizing bootstraps errors ... right now they're pretty inconsistent.
(-bash@build-server) ~/rustc $ rg println src/bootstrap/
src/bootstrap/config.rs
565: println!("failed to parse TOML configuration '{}': {}", file.display(), err);
src/bootstrap/setup.rs
81: println!("error: unrecognized option '{}'", input.trim());
82: println!("note: press Ctrl+C to exit");
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.
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.
i might format "the static max level is XXX" as a note:
but take it or leave it.
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.
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.
this looks rad!
Is this waiting on anything? I'd love to have it in rustc :) |
I can squash the commit history if you like, not sure what the policy is for that. |
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.
looks good to me!
Nope, everything looks fine, I just had a bunch of other things to take care of. Happy to merge it now! Note that the
We'll squash the PR when merging it. See https://github.com/tokio-rs/tracing/blob/master/CONTRIBUTING.md#commit-squashing :) |
…io-rs#990) ## Motivation Fixes tokio-rs#975. ## Solution This implements the warning in `tracing-subscriber` only, as mentioned in tokio-rs#975 (comment). It warns whenever directives are parsed, including programmatically and through environment variables. It does not include the suggested new API which returns the filters that wouldn't be parsed. - List filters that would be ignored - Mention 'static max level' - Describe how to enable the logging Example output: ``` $ RUST_LOG=off,debug,silenced[x]=trace cargo run -q warning: some trace filter directives would enable traces that are disabled statically | `debug` would enable the DEBUG level for all targets | `silenced[x]=trace` would enable the TRACE level for the `silenced` target = note: the static max level is info = note: to enable DEBUG logging, remove the `max_level_info` feature ``` ![image](https://user-images.githubusercontent.com/23638587/95243324-77dc6a00-07de-11eb-8ed3-6ee2109940d4.png)
* upstream/master: subscriber: warn if trying to enable a statically disabled level (tokio-rs#990) subscriber: use macros for module declarations (tokio-rs#1009) chore: remove `stdlib.rs` (tokio-rs#1008) core: fix linked list tests reusing `Registration`s (tokio-rs#1016) subscriber: support dash in target names (tokio-rs#1012) docs: switch to intra-doc links in tracing-core (tokio-rs#1010) tracing-opentelemetry: implement additional record types (bool, i64, u64) (tokio-rs#1007) core: add intrusive linked list for callsite registry (tokio-rs#988) serde: allow tracing-serde to work on no_std. (tokio-rs#960) tracing: remove `Into<Option<Id>>` impl for `Span` (tokio-rs#1003) tracing: make `Entered` `!Send` (tokio-rs#1001) chore: fix nightly clippy warnings (tokio-rs#991) chore: bump all crate versions (tokio-rs#998) macros: fix the `tracing-macros` crate not compiling (tokio-rs#1000) tracing: prepare to release 0.1.21 (tokio-rs#997) core: prepare to release 0.1.17 (tokio-rs#996) subscriber: make `PartialOrd` & `Ord` impls more correct (tokio-rs#995) core, tracing: don't inline dispatcher::get_default (tokio-rs#994) core: make `Level` and `LevelFilter` `Copy` (tokio-rs#992)
The primary motivation is to get the changes from tokio-rs/tracing#990. Example output: ``` $ RUSTDOC_LOG=debug rustdoc +rustc2 warning: some trace filter directives would enable traces that are disabled statically | `debug` would enable the DEBUG level for all targets = note: the static max level is `info` = help: to enable DEBUG logging, remove the `max_level_info` feature ``` - Remove useless test This was testing for an ICE when passing `RUST_LOG=rustc_middle`. I noticed it because it started giving the tracing warning (because tests are not run with debug-logging enabled). Since this bug seems unlikely to re-occur, I just removed it altogether.
Upgrade to tracing-subscriber 0.2.13 The primary motivation is to get the changes from tokio-rs/tracing#990. Example output: ``` $ RUSTDOC_LOG=debug rustdoc +rustc2 warning: some trace filter directives would enable traces that are disabled statically | `debug` would enable the DEBUG level for all targets = note: the static max level is `info` = help: to enable DEBUG logging, remove the `max_level_info` feature ``` r? `@Mark-Simulacrum` cc `@hawkw` ❤️
…spatch-as-ref-tokio-rs#455 * upstream/master: (28 commits) opentelemetry: prepare for 0.8.0 release (tokio-rs#1036) docs: add favicon for extra pretty docs (tokio-rs#1033) subscriber: fix `reload` ergonomics (tokio-rs#1035) chore(deps): update crossbeam-channel requirement from 0.4.2 to 0.5.0 (tokio-rs#1031) opentelemetry: Assign default ids if missing (tokio-rs#1027) chore: remove deprecated add-path from CI (tokio-rs#1026) attributes: fix `#[instrument(err)]` in case of early returns (tokio-rs#1006) core: remove mandatory liballoc dependency with no-std (tokio-rs#1017) chore(deps): update cfg-if requirement from 0.1.10 to 1.0.0 (tokio-rs#1023) subscriber: warn if trying to enable a statically disabled level (tokio-rs#990) subscriber: use macros for module declarations (tokio-rs#1009) chore: remove `stdlib.rs` (tokio-rs#1008) core: fix linked list tests reusing `Registration`s (tokio-rs#1016) subscriber: support dash in target names (tokio-rs#1012) docs: switch to intra-doc links in tracing-core (tokio-rs#1010) tracing-opentelemetry: implement additional record types (bool, i64, u64) (tokio-rs#1007) core: add intrusive linked list for callsite registry (tokio-rs#988) serde: allow tracing-serde to work on no_std. (tokio-rs#960) tracing: remove `Into<Option<Id>>` impl for `Span` (tokio-rs#1003) tracing: make `Entered` `!Send` (tokio-rs#1001) ...
…cros * upstream/master: (30 commits) chore(deps): update pin-project requirement from 0.4 to 1.0 (tokio-rs#1038) chore: remove duplicated section from tracing/README.md (tokio-rs#1046) opentelemetry: prepare for 0.8.0 release (tokio-rs#1036) docs: add favicon for extra pretty docs (tokio-rs#1033) subscriber: fix `reload` ergonomics (tokio-rs#1035) chore(deps): update crossbeam-channel requirement from 0.4.2 to 0.5.0 (tokio-rs#1031) opentelemetry: Assign default ids if missing (tokio-rs#1027) chore: remove deprecated add-path from CI (tokio-rs#1026) attributes: fix `#[instrument(err)]` in case of early returns (tokio-rs#1006) core: remove mandatory liballoc dependency with no-std (tokio-rs#1017) chore(deps): update cfg-if requirement from 0.1.10 to 1.0.0 (tokio-rs#1023) subscriber: warn if trying to enable a statically disabled level (tokio-rs#990) subscriber: use macros for module declarations (tokio-rs#1009) chore: remove `stdlib.rs` (tokio-rs#1008) core: fix linked list tests reusing `Registration`s (tokio-rs#1016) subscriber: support dash in target names (tokio-rs#1012) docs: switch to intra-doc links in tracing-core (tokio-rs#1010) tracing-opentelemetry: implement additional record types (bool, i64, u64) (tokio-rs#1007) core: add intrusive linked list for callsite registry (tokio-rs#988) serde: allow tracing-serde to work on no_std. (tokio-rs#960) ...
…gger * upstream/master: (31 commits) chore: fix tracing-macros::dbg (tokio-rs#1054) chore(deps): update pin-project requirement from 0.4 to 1.0 (tokio-rs#1038) chore: remove duplicated section from tracing/README.md (tokio-rs#1046) opentelemetry: prepare for 0.8.0 release (tokio-rs#1036) docs: add favicon for extra pretty docs (tokio-rs#1033) subscriber: fix `reload` ergonomics (tokio-rs#1035) chore(deps): update crossbeam-channel requirement from 0.4.2 to 0.5.0 (tokio-rs#1031) opentelemetry: Assign default ids if missing (tokio-rs#1027) chore: remove deprecated add-path from CI (tokio-rs#1026) attributes: fix `#[instrument(err)]` in case of early returns (tokio-rs#1006) core: remove mandatory liballoc dependency with no-std (tokio-rs#1017) chore(deps): update cfg-if requirement from 0.1.10 to 1.0.0 (tokio-rs#1023) subscriber: warn if trying to enable a statically disabled level (tokio-rs#990) subscriber: use macros for module declarations (tokio-rs#1009) chore: remove `stdlib.rs` (tokio-rs#1008) core: fix linked list tests reusing `Registration`s (tokio-rs#1016) subscriber: support dash in target names (tokio-rs#1012) docs: switch to intra-doc links in tracing-core (tokio-rs#1010) tracing-opentelemetry: implement additional record types (bool, i64, u64) (tokio-rs#1007) core: add intrusive linked list for callsite registry (tokio-rs#988) ...
…spatch-as-owned-tokio-rs#455 * upstream/master: (34 commits) subscriber: remove TraceLogger (tokio-rs#1052) subscriber: make Registry::enter/exit much faster (tokio-rs#1058) chore(deps): update env_logger requirement from 0.7 to 0.8 (tokio-rs#1050) chore: fix tracing-macros::dbg (tokio-rs#1054) chore(deps): update pin-project requirement from 0.4 to 1.0 (tokio-rs#1038) chore: remove duplicated section from tracing/README.md (tokio-rs#1046) opentelemetry: prepare for 0.8.0 release (tokio-rs#1036) docs: add favicon for extra pretty docs (tokio-rs#1033) subscriber: fix `reload` ergonomics (tokio-rs#1035) chore(deps): update crossbeam-channel requirement from 0.4.2 to 0.5.0 (tokio-rs#1031) opentelemetry: Assign default ids if missing (tokio-rs#1027) chore: remove deprecated add-path from CI (tokio-rs#1026) attributes: fix `#[instrument(err)]` in case of early returns (tokio-rs#1006) core: remove mandatory liballoc dependency with no-std (tokio-rs#1017) chore(deps): update cfg-if requirement from 0.1.10 to 1.0.0 (tokio-rs#1023) subscriber: warn if trying to enable a statically disabled level (tokio-rs#990) subscriber: use macros for module declarations (tokio-rs#1009) chore: remove `stdlib.rs` (tokio-rs#1008) core: fix linked list tests reusing `Registration`s (tokio-rs#1016) subscriber: support dash in target names (tokio-rs#1012) ...
Motivation
Fixes #975.
Solution
This implements the warning in
tracing-subscriber
only, as mentioned in #975 (comment). It warns whenever directives are parsed, including programmatically and through environment variables. It does not include the suggested new API which returns the filters that wouldn't be parsed.Example output: