Skip to content

Commit

Permalink
subscriber: let EnvFIlter's filter disabled help say help without a…
Browse files Browse the repository at this point in the history
…nsi_term (#2029)

## Motivation

EnvFilter with ansi_term will say something like the following when
statically disabled filters are present:

```
warning: some trace filter directives would enable traces ...
 = note: the static max level is `LEVEL`
 = help: to enable LEVEL logging, ...
```

Without the ansi_term feature, it instead says something like the
following:

```
warning: some trace filter directives would enable traces ...
note: the static max level is `LEVEL`
note: to enable LEVEL logging, ...
```

This is due to a simple error in cfg'd code that ignores the requested
prefix and always uses `note:` when `not(feature = "ansi_term")`.

## Solution

Use the unused `prefix` variable to do what it does when `feature =
"ansi_term"`.

The output without ansi_term is now

```
warning: some trace filter directives would enable traces ...
note: the static max level is `LEVEL`
help: to enable LEVEL logging, ...
```
  • Loading branch information
CAD97 authored and hawkw committed Mar 29, 2022
1 parent 7921a3b commit 30204cb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tracing-subscriber/src/filter/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl EnvFilter {
};
let ctx_prefixed = |prefix: &str, msg: &str| {
#[cfg(not(feature = "ansi_term"))]
let msg = format!("note: {}", msg);
let msg = format!("{} {}", prefix, msg);
#[cfg(feature = "ansi_term")]
let msg = {
let mut equal = Color::Fixed(21).paint("="); // dark blue
Expand Down

0 comments on commit 30204cb

Please sign in to comment.