Repository navigation
Core: ignore empty VICTORY_LOG and RUST_LOG values instead of overriding default log level - #2578
reeledMarek wants to merge 1 commit into
Conversation
lcg007xd-c
left a comment
There was a problem hiding this comment.
Verified on Linux (Rust 1.99.0)
Branch: current main (13f91ca) + this PR (merges cleanly; it also merges cleanly with #2579).
cargo test --locked -p victory-core: 14 passed.- With the
.filter(|v| !v.is_empty())inbuild_filterremoved,empty_victory_log_falls_back_to_rust_log_and_defaultfails (left: "", right: "warn"). So the test pins the empty-value fix. For reference,EnvFilter::new("")is an ERROR-only filter (max_level_hint() == ERROR), so on mainVICTORY_LOG=silently drops everything below error. cargo clippy --locked --target x86_64-pc-windows-msvc -p victory-core --all-targets -- -D warnings: clean, same as main.
Findings
-
Whitespace-only values are not handled, contrary to the description. The description says "empty or whitespace-only
VICTORY_LOG/RUST_LOGvalues are skipped cleanly, falling through to the next env var", and that the tests cover whitespace. The code filters onlyis_empty()(logging.rs:34), and the test has no whitespace case. I added a temporary test callingbuild_filter("info", ..)withVICTORY_LOG = " "andRUST_LOG = "warn". It returnsinfo:EnvFilter::try_new(" ")fails, soRUST_LOGis skipped and the default wins.
Suggestion:.filter(|v| !v.trim().is_empty()), plus a" "case in the test. Or drop the whitespace claim from the description. -
Related, already on main, not introduced here: a
VICTORY_LOGthat fails to parse also skipsRUST_LOG, because.and_then(|v| EnvFilter::try_new(v).ok())runs after theor_else. If falling through to the next variable is the intent, apply the parse insideget, so thatget("VICTORY_LOG").or_else(|| get("RUST_LOG"))falls through on an invalid value as well. #266 (closed, folded into #241, which was closed unmerged) printed a warning for an unparsable filter. It could be worth picking up while this function is being touched.
Not verified
- Behaviour through
inititself. The global subscriber can't be re-initialised in a test, so onlybuild_filteris covered.
Reviewed with Claude Code.
…es instead of overriding default log level
|
Automated triage for the maintainers. Merge candidate. Re-reviewed at Reply to the author: thanks, all points from the earlier triage are addressed. CI: Generated by Claude Code |
3c2a8fa to
f71ae4f
Compare
|
Updated to address the triage and @lcg007xd-c's review:
|
…es instead of overriding default log level
|
Independent local verification of PR #2578 (head
Note: the assertion inspects |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Filtering out empty and whitespace-only values before resolving VICTORY_LOG -> RUST_LOG -> default_level fixes the blank-env override cleanly, preserves fallback to default_level when a selected non-blank directive fails to parse, and injecting the env lookup keeps the unit test free of process-wide env/subscriber races. (A small optional addition would be a parse-error case like VICTORY_LOG=victory_core=bogus with RUST_LOG=warn, since bare bogus is accepted as a target name by tracing-subscriber.)
Local verification at f71ae4fe (and merged cleanly onto origin/main 63bcca43): rustfmt --edition 2024 --check clean, xtask policy (191 files ok), cargo clippy -p victory-core --all-targets (default and --all-features), and cargo test -p victory-core (debug, --all-features, --release, and merged onto origin/main: 14/14) all passed.
Summary
In
victory-core/src/logging.rs, settingVICTORY_LOG=""orRUST_LOG=""previously took precedence over the default filter becausestd::env::varreturnsOk(""), silently producing an empty filter instead of falling back to the default log level.Now empty or whitespace-only
VICTORY_LOG/RUST_LOGvalues are skipped cleanly, falling through to the next env var or the default filter.Testing
cargo test -p victory-core --locked(14/14 passed, including synthetic tests for empty/whitespace env values)cargo clippy -p victory-core --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings(clean)cargo test -p xtask --locked(6/6 passed)