vague
July 23, 2024, 3:31am
1
From EnvFilter in tracing_subscriber::filter - Rust and for the following code, I'd expect some valid syntax should have worked.
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
#[macro_use]
extern crate tracing;
fn main() {
tracing_subscriber::registry()
.with(fmt::layer())
.with(EnvFilter::from_default_env())
.init();
f();
}
fn f() {
let b = 1;
debug_span!(target: "my", "a").in_scope(|| debug!(b));
}
RUST_LOG=[a] cargo r # good output: DEBUG a: tracing_filter: b=1
RUST_LOG=[{b}] cargo r # good as above
RUST_LOG=[{b=1}] cargo r # no output: bad
RUST_LOG=[a{b}] cargo r # no output: bad
# specify the target
RUST_LOG=my cargo r # no output: bad
RUST_LOG=my=debug cargo r # no output: bad
RUST_LOG=my[a]=debug cargo r # good: DEBUG a: tracing_filter: b=1
RUST_LOG=my[{b}]=debug cargo r # no output: bad
vague
July 23, 2024, 4:52am
2
It turns out the functionality is buggy and documentation on EnvFilter is out of date for years.
opened 03:39PM - 10 Jan 21 UTC
kind/bug
crate/subscriber
## Bug Report
<!--
Thank you for reporting an issue.
Please fill in as much… of the template below as you're able.
-->
### Version
<!--
List the versions of all `tracing` crates you are using. The easiest way to get
this information is using `cargo-tree`.
`cargo install cargo-tree`
(see install here: https://github.com/sfackler/cargo-tree)
Then:
`cargo tree | grep tracing`
-->
master branch
cargo build --exmaples
$ cargo --version
cargo 1.47.0 (f3c7e066a 2020-08-28)
### Platform
<!---
Output of `uname -a` (UNIX), or version and 32 or 64-bit (Windows)
-->
Linux 4.9
### Crates
<!--
If known, please specify the affected tracing crates. Otherwise, delete this
section.
-->
### Description
<!--
Enter your issue details below this comment.
One way to structure the description:
<short summary of the bug>
I tried this code:
<code sample that causes the bug>
I expected to see this happen: <explanation>
Instead, this happened: <explanation>
-->
When I run the subscriber-filter example like this, it doesn't work like I thought it would.
``` bash
RUST_LOG=[shave{yak=2}] ../target/debug/examples/subscriber-filter
```
Output nothing.
Run like this, it work:
``` bash
$ RUST_LOG=[shave{yak}] ../target/debug/examples/subscriber-filter
Jan 10 23:28:31.626 TRACE shave{yak=1}: subscriber_filter::yak_shave: hello! I'm gonna shave a yak excitement="yay!"
Jan 10 23:28:31.626 TRACE shave{yak=1}: subscriber_filter::yak_shave: yak shaved successfully
Jan 10 23:28:31.626 TRACE shave{yak=2}: subscriber_filter::yak_shave: hello! I'm gonna shave a yak excitement="yay!"
Jan 10 23:28:31.626 TRACE shave{yak=2}: subscriber_filter::yak_shave: yak shaved successfully
Jan 10 23:28:31.626 TRACE shave{yak=3}: subscriber_filter::yak_shave: hello! I'm gonna shave a yak excitement="yay!"
Jan 10 23:28:31.627 WARN shave{yak=3}: subscriber_filter::yak_shave: could not locate yak
```
I tried :
```
RUST_LOG=[shave{yak=\"2\"}]
RUST_LOG=[shave{yak='2'}]
RUST_LOG="[shave{yak=\"2\"}]"
```
none of them worked.
Thanks all.