Open abatilo opened 5 months ago
After doing some more debugging:
use tracing::{debug, info};
use tracing_subscriber::EnvFilter;
fn main() {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
info!("INFO Hello World!");
debug!("DEBUG Hello World!");
}
Explicitly calling with_env_filter
makes this work:
⇒ RUST_LOG=debug cargo run
Compiling trace-example v0.1.0 (/Users/aaron/temp/trace-example)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.16s
Running `target/debug/trace-example`
2024-06-02T17:03:28.774980Z INFO trace_example: INFO Hello World!
2024-06-02T17:03:28.774997Z DEBUG trace_example: DEBUG Hello World!
But this is in direct conflict with what the README.md
states about the global collector already being configured by RUST_LOG
https://github.com/tokio-rs/tracing/blob/382ee01dc1cf428c071cad1e3f2e6c6427e70f87/README.md#L63-L64
You're right that this is a big. I'd say it's a documentation bug though as it never worked as in the example with env filter being loaded by default.
Thanks @mladedav. This was my first day looking into Rust and that was a very confusing experience 😅.
I'm happy to make the contribution but I'm not sure if I should update the docs to include the EnvFilter
and mention the required feature
on the dep, or if I should just remove the comment, etc. Thoughts?
Sorry for mystifying you here, I didn't notice the two init
s either.
Bug Report
Version
Platform
Description
Here is my sample code where I try to print both
info
anddebug
logs:And here are the outputs. With
RUST_LOG=info
, I see the info log:And with
RUST_LOG=debug
, I still only see the info log: