You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tracing = "0.1.41"
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.19", features = ["chrono", "env-filter"] }
Platform
4.18.0-305.3.1.el8.x86_64 #1 SMP Tue Jun 1 16:14:33 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
CentOS
Crates
tracing
tracing-subscriber
Description
I am experiencing an issue where some logs do not appear when using my_crate=debug in the RUST_LOG environment variable. This problem occurs in the actual code, but the logs do appear when I use the same logging setup in a test function.
Steps to Reproduce:
Set the RUST_LOG environment variable to my_crate=debug.
Log some messages using event!(Level::DEBUG, "debug message").
The logs do not appear when running the main application, but they show up correctly in the test function with the same logging setup.
pubfnsetup_logging_to_stderr_and_rolling_file(filename_prefix:&str,// stderr_log_level: filter::LevelFilter,) -> Result<(),Error>{let stderr_log_level = filter::LevelFilter::INFO;let stderr_layer = tracing_subscriber::fmt::layer().pretty().with_writer(io::stderr);let tmp_dir = get_tmp_dir();let file_layer = tracing_subscriber::fmt::layer().pretty().with_writer(RollingFileAppender::builder().rotation(Rotation::DAILY).filename_prefix(filename_prefix).filename_suffix("log").build(&tmp_dir)?,);
tracing_subscriber::registry().with(
stderr_layer
.with_timer(ChronoLocal::rfc_3339()).with_file(false).with_line_number(false).with_target(false).with_filter(get_env_filter(stderr_log_level)?),).with(
file_layer
.with_timer(ChronoLocal::rfc_3339()).with_ansi(false).with_filter(get_env_filter(filter::LevelFilter::DEBUG)?),).try_init()?;let log_dir_abs_path = matchPath::new(&tmp_dir).canonicalize(){Ok(v) => v,Err(_) => PathBuf::from(tmp_dir),};// event!(Level::INFO, "log dir = {}", log_dir_abs_path.display());Ok(())}#[tokio::main]fnmain() -> Result<(),Error>{setup_logging_to_stderr_and_rolling_file("log")?;event!(Level::DEBUG,"This is a debug message");// Simulate some other work
tokio::time::sleep(std::time::Duration::from_secs(1)).await;event!(Level::WARN,"This is a warning message");}
Expected Behavior:
All logs at the DEBUG level (and higher) should be displayed when my_crate=debug is set in the RUST_LOG environment variable.
Actual Behavior:
Logs at the DEBUG level are missing when my_crate=debug is set, and only higher-level logs (e.g., WARN, ERROR) appear. However, the same setup works fine in the test function.
The text was updated successfully, but these errors were encountered:
Crispy13
changed the title
EnvFilter
Using with envfilter skips some logs
Feb 8, 2025
Bug Report
Version
tracing = "0.1.41"
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.19", features = ["chrono", "env-filter"] }
Platform
4.18.0-305.3.1.el8.x86_64 #1 SMP Tue Jun 1 16:14:33 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
CentOS
Crates
tracing
tracing-subscriber
Description
I am experiencing an issue where some logs do not appear when using
my_crate=debug
in theRUST_LOG
environment variable. This problem occurs in the actual code, but the logs do appear when I use the same logging setup in a test function.Steps to Reproduce:
RUST_LOG
environment variable tomy_crate=debug
.event!(Level::DEBUG, "debug message")
.Expected Behavior:
All logs at the
DEBUG
level (and higher) should be displayed whenmy_crate=debug
is set in theRUST_LOG
environment variable.Actual Behavior:
Logs at the
DEBUG
level are missing whenmy_crate=debug
is set, and only higher-level logs (e.g.,WARN
,ERROR
) appear. However, the same setup works fine in the test function.The text was updated successfully, but these errors were encountered: