Core: ignore empty VICTORY_LOG and RUST_LOG values instead of overriding default log level #2576

Open
reeledMarek wants to merge 1 commit from upstream-pr/2578 into main
reeledMarek commented 2026-11-25 16:08:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T16:08:50Z.


Summary

In victory-core/src/logging.rs, setting VICTORY_LOG="" or RUST_LOG="" previously took precedence over the default filter because std::env::var returns Ok(""), silently producing an empty filter instead of falling back to the default log level.

Now empty or whitespace-only VICTORY_LOG / RUST_LOG values 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)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6608589517 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2578). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T16:08:50Z. --- ### Summary In `victory-core/src/logging.rs`, setting `VICTORY_LOG=""` or `RUST_LOG=""` previously took precedence over the default filter because `std::env::var` returns `Ok("")`, silently producing an empty filter instead of falling back to the default log level. Now empty or whitespace-only `VICTORY_LOG` / `RUST_LOG` values 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)
lcg007xd-c commented 2026-11-25 21:21:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lcg007xd-c on 2026-11-25T21:21:53Z.

Review: COMMENTED


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()) in build_filter removed, empty_victory_log_falls_back_to_rust_log_and_default fails (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 main VICTORY_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

  1. Whitespace-only values are not handled, contrary to the description. The description says "empty or whitespace-only VICTORY_LOG / RUST_LOG values are skipped cleanly, falling through to the next env var", and that the tests cover whitespace. The code filters only is_empty() (logging.rs:34), and the test has no whitespace case. I added a temporary test calling build_filter("info", ..) with VICTORY_LOG = " " and RUST_LOG = "warn". It returns info: EnvFilter::try_new(" ") fails, so RUST_LOG is 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.

  2. Related, already on main, not introduced here: a VICTORY_LOG that fails to parse also skips RUST_LOG, because .and_then(|v| EnvFilter::try_new(v).ok()) runs after the or_else. If falling through to the next variable is the intent, apply the parse inside get, so that get("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 init itself. The global subscriber can't be re-initialised in a test, so only build_filter is covered.

Reviewed with Claude Code.

<!-- greyfinch-sync:Marvisak/VIctory:review:6065156161 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2578#pullrequestreview-6065156161). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T21:21:53Z. **Review:** COMMENTED --- ### 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())` in `build_filter` removed, `empty_victory_log_falls_back_to_rust_log_and_default` fails (`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 main `VICTORY_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 1. **Whitespace-only values are not handled, contrary to the description.** The description says "empty or whitespace-only `VICTORY_LOG` / `RUST_LOG` values are skipped cleanly, falling through to the next env var", and that the tests cover whitespace. The code filters only `is_empty()` (logging.rs:34), and the test has no whitespace case. I added a temporary test calling `build_filter("info", ..)` with `VICTORY_LOG = " "` and `RUST_LOG = "warn"`. It returns `info`: `EnvFilter::try_new(" ")` fails, so `RUST_LOG` is 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. 2. **Related, already on main, not introduced here:** a `VICTORY_LOG` that fails to parse also skips `RUST_LOG`, because `.and_then(|v| EnvFilter::try_new(v).ok())` runs after the `or_else`. If falling through to the next variable is the intent, apply the parse inside `get`, so that `get("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 `init` itself. The global subscriber can't be re-initialised in a test, so only `build_filter` is covered. Reviewed with Claude Code.
Marvisak commented 2026-11-25 23:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:17:55Z.


Automated triage for the maintainers.

Merge candidate. Re-reviewed at f71ae4f. In crates/victory-core/src/logging.rs, build_filter now skips VICTORY_LOG/RUST_LOG values that are empty or whitespace-only (!v.trim().is_empty()), so such a value no longer gives an error-only filter or hides RUST_LOG. The function takes an injected env closure, so the test needs no process environment. The test covers empty, spaces-only and tab values, and the fall-through to the default level. The module doc now states the rule.

Reply to the author: thanks, all points from the earlier triage are addressed.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176186994 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2578#issuecomment-7176186994). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:17:55Z. --- <!-- victory-triage v1 head=f71ae4fea662a171768f0e404f118a577b5262ea verdict=merge-candidate at=2026-11-26T07:18:15Z --> Automated triage for the maintainers. **Merge candidate.** Re-reviewed at `f71ae4f`. In `crates/victory-core/src/logging.rs`, `build_filter` now skips `VICTORY_LOG`/`RUST_LOG` values that are empty or whitespace-only (`!v.trim().is_empty()`), so such a value no longer gives an error-only filter or hides `RUST_LOG`. The function takes an injected `env` closure, so the test needs no process environment. The test covers empty, spaces-only and tab values, and the fall-through to the default level. The module doc now states the rule. **Reply to the author:** thanks, all points from the earlier triage are addressed. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
reeledMarek commented 2026-11-26 06:03:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:56:06Z.


Updated to address the triage and @lcg007xd-c's review:

  • Filtered on !v.trim().is_empty() in build_filter so whitespace-only VICTORY_LOG / RUST_LOG values also fall through cleanly.
  • Added whitespace-only test cases (" " and " \t ") to empty_victory_log_falls_back_to_rust_log_and_default.
  • Updated the module doc comment in crates/victory-core/src/logging.rs to note that empty or whitespace-only values are ignored.
  • Rebased onto main (63bcca4), verified cargo test -p victory-core --locked (14/14 passed) and Windows cross-clippy.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7183937886 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2578#issuecomment-7183937886). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T05:56:06Z. --- Updated to address the triage and @lcg007xd-c's review: - Filtered on `!v.trim().is_empty()` in `build_filter` so whitespace-only `VICTORY_LOG` / `RUST_LOG` values also fall through cleanly. - Added whitespace-only test cases (`" "` and `" \t "`) to `empty_victory_log_falls_back_to_rust_log_and_default`. - Updated the module doc comment in `crates/victory-core/src/logging.rs` to note that empty or whitespace-only values are ignored. - Rebased onto `main` (`63bcca4`), verified `cargo test -p victory-core --locked` (14/14 passed) and Windows cross-clippy.
fuzeofficlal commented 2026-11-26 16:02:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T16:02:22Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6077206394 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2578#pullrequestreview-6077206394). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T16:02:22Z. **Review:** APPROVED --- 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.
cloph-dsp commented 2026-11-26 16:05:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-26T15:40:12Z.


Independent local verification of PR #2578 (head f71ae4fea662a171768f0e404f118a577b5262ea), Windows / Rust 1.100.0 MSVC, per-worktree CARGO_TARGET_DIR=D:\Victory-Contrib\target-2578, no game data.

  • cargo test --locked -p victory-core --lib -- logging::tests::empty_victory_log_falls_back_to_rust_log_and_default --exact --quiet → 1 passed, 0 failed, 13 filtered, exit 0.
  • New test name is absent from the merge base 63bcca43 (negative control).
  • git diff --check 63bcca43..HEAD → exit 0.

Note: the assertion inspects EnvFilter::to_string() formatting from tracing-subscriber, which is version-sensitive; I did not vary dependency versions. CPU-only; GPU/driver N/A. AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7196588316 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2578#issuecomment-7196588316). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-26T15:40:12Z. --- Independent local verification of PR #2578 (head `f71ae4fea662a171768f0e404f118a577b5262ea`), Windows / Rust 1.100.0 MSVC, per-worktree `CARGO_TARGET_DIR=D:\Victory-Contrib\target-2578`, no game data. - `cargo test --locked -p victory-core --lib -- logging::tests::empty_victory_log_falls_back_to_rust_log_and_default --exact --quiet` → 1 passed, 0 failed, 13 filtered, exit 0. - New test name is absent from the merge base `63bcca43` (negative control). - `git diff --check 63bcca43..HEAD` → exit 0. Note: the assertion inspects `EnvFilter::to_string()` formatting from tracing-subscriber, which is version-sensitive; I did not vary dependency versions. CPU-only; GPU/driver N/A. AI-assisted (Hy4 flash).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2578:upstream-pr/2578'
git switch 'upstream-pr/2578'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2578'
git switch 'upstream-pr/2578'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2578'
git switch 'upstream-pr/2578'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2578'
git switch 'main'
git merge --squash 'upstream-pr/2578'
git switch 'main'
git merge --ff-only 'upstream-pr/2578'
git switch 'main'
git merge 'upstream-pr/2578'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2576
No description provided.