core: an empty DARNER_LOG means unset, not "log nothing" #572

Open
qnjk wants to merge 1 commit from qnjk/Darner:logging-empty-filter into Main
Contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: logging::init reads DARNER_LOG with std::env::var("DARNER_LOG").ok() and asks for RUST_LOG only when that is None:

    let darner_log = std::env::var("DARNER_LOG").ok();
    let rust_log = darner_log.is_none().then(|| std::env::var("RUST_LOG").ok()).flatten();
    

    and resolve_filter then does darner_log.or(rust_log).and_then(|v| EnvFilter::try_new(v).ok()). A defined-but-empty variable is Ok(""), not None, and EnvFilter::try_new("") returns Ok with zero directives — a filter that enables nothing. So DARNER_LOG= (reachable from darner play --set DARNER_LOG=, or from any launcher that passes a variable through with nothing set) logged not one line to the console or to the log file darner play names, skipped the RUST_LOG fallback the module doc promises, and never reached the default level either. It was the only environment read in the crate where "" meant "log nothing" instead of "unset": config.rs:100's env_path and this file's own DARNER_LOG_FILE both filter empty.

  • This change adds one helper, non_empty(value: Option<&str>), which drops a blank value (including whitespace-only), and applies it to both lookups inside resolve_filter, keeping the order DARNER_LOG → RUST_LOG → default_level. init now reads both variables; which one wins stays resolve_filter's single decision, so the fallback is actually reachable when DARNER_LOG is present but empty. No other behaviour changes.

How it was tested

  • Tested revision: 7f51e5e (one commit on c8258f9).
  • Commands and results:
    • cargo test --locked -p darner-core --lib — 51 passed, 0 failed.
    • New test logging::tests::empty_log_variables_count_as_unset pins: empty DARNER_LOG uses RUST_LOG (error); empty RUST_LOG uses the default (info); both empty uses the default; whitespace-only counts as empty; a non-empty DARNER_LOG still wins over an empty RUST_LOG. It touches no environment — the helper takes the values as arguments.
    • Fail-before, with only the production edit reverted and the test kept:
      logging::tests::empty_log_variables_count_as_unset ... FAILED
      panicked at crates/darner-core/src/logging.rs:375:
      assertion `left == right` failed
        left: ""
      
    • cargo clippy --locked -p darner-core --all-targets -- -D warnings passes.
  • Changes a default: no. A non-empty DARNER_LOG/RUST_LOG is used exactly as before; only a blank value changes, and it now means "unset" as it does everywhere else in the tree.
  • A/B result: not applicable — no default changes and no speed claim.
  • Gates run on that revision:
    • Gate 1, cargo clippy --workspace --all-targets --locked -- -D warnings: passes.
    • Gate 2, cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passes.
    • Gate 3, cargo test --workspace --locked: not run to completion here; the pre-existing darner-gpu test deadlock (#224) and the darner-shader waterfall fixture failure (#227) make the whole-workspace run non-green on this machine, and neither crate is touched by this change. darner-core's suite is green (51 passed).
  • Gameplay, when relevant: no gameplay run; this is the logging filter, it cannot alter title behaviour.
  • Shader wave sizes tested, when relevant: not applicable.
  • Hardware dependence: none.
  • Coverage gaps: the empty value was not reproduced end to end through darner play --set DARNER_LOG=; the helper and the ordering are pinned by the test. The log-file path (DARNER_LOG_FILE) was not re-checked with an empty DARNER_LOG.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
    • Not run in gameplay: the logging filter cannot change what the title does. The evidence is the test, which fails on main.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. (cargo xtask policy: 576 files ok.)
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found. No open pull request changes crates/darner-core/src/logging.rs (checked against the file list of all 189 open pull requests), and no open or closed issue mentions DARNER_LOG being empty.
  • Replaces or overlaps: none found
## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: `logging::init` reads `DARNER_LOG` with `std::env::var("DARNER_LOG").ok()` and asks for `RUST_LOG` only when that is `None`: ```rust let darner_log = std::env::var("DARNER_LOG").ok(); let rust_log = darner_log.is_none().then(|| std::env::var("RUST_LOG").ok()).flatten(); ``` and `resolve_filter` then does `darner_log.or(rust_log).and_then(|v| EnvFilter::try_new(v).ok())`. A **defined-but-empty** variable is `Ok("")`, not `None`, and `EnvFilter::try_new("")` returns `Ok` with zero directives — a filter that enables nothing. So `DARNER_LOG=` (reachable from `darner play --set DARNER_LOG=`, or from any launcher that passes a variable through with nothing set) logged not one line to the console or to the log file `darner play` names, skipped the `RUST_LOG` fallback the module doc promises, and never reached the default level either. It was the only environment read in the crate where `""` meant "log nothing" instead of "unset": `config.rs:100`'s `env_path` and this file's own `DARNER_LOG_FILE` both filter empty. - This change adds one helper, `non_empty(value: Option<&str>)`, which drops a blank value (including whitespace-only), and applies it to both lookups inside `resolve_filter`, keeping the order `DARNER_LOG` → `RUST_LOG` → `default_level`. `init` now reads both variables; which one wins stays `resolve_filter`'s single decision, so the fallback is actually reachable when `DARNER_LOG` is present but empty. No other behaviour changes. ## How it was tested - Tested revision: `7f51e5e` (one commit on `c8258f9`). - Commands and results: - `cargo test --locked -p darner-core --lib` — 51 passed, 0 failed. - New test `logging::tests::empty_log_variables_count_as_unset` pins: empty `DARNER_LOG` uses `RUST_LOG` (`error`); empty `RUST_LOG` uses the default (`info`); both empty uses the default; whitespace-only counts as empty; a non-empty `DARNER_LOG` still wins over an empty `RUST_LOG`. It touches no environment — the helper takes the values as arguments. - Fail-before, with only the production edit reverted and the test kept: ``` logging::tests::empty_log_variables_count_as_unset ... FAILED panicked at crates/darner-core/src/logging.rs:375: assertion `left == right` failed left: "" ``` - `cargo clippy --locked -p darner-core --all-targets -- -D warnings` passes. - Changes a default: no. A non-empty `DARNER_LOG`/`RUST_LOG` is used exactly as before; only a blank value changes, and it now means "unset" as it does everywhere else in the tree. - A/B result: not applicable — no default changes and no speed claim. - Gates run on that revision: - Gate 1, `cargo clippy --workspace --all-targets --locked -- -D warnings`: passes. - Gate 2, `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passes. - Gate 3, `cargo test --workspace --locked`: not run to completion here; the pre-existing `darner-gpu` test deadlock (#224) and the `darner-shader` waterfall fixture failure (#227) make the whole-workspace run non-green on this machine, and neither crate is touched by this change. `darner-core`'s suite is green (51 passed). - Gameplay, when relevant: no gameplay run; this is the logging filter, it cannot alter title behaviour. - Shader wave sizes tested, when relevant: not applicable. - Hardware dependence: none. - Coverage gaps: the empty value was not reproduced end to end through `darner play --set DARNER_LOG=`; the helper and the ordering are pinned by the test. The log-file path (`DARNER_LOG_FILE`) was not re-checked with an empty `DARNER_LOG`. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - Not run in gameplay: the logging filter cannot change what the title does. The evidence is the test, which fails on `main`. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. (`cargo xtask policy`: 576 files ok.) - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found. No open pull request changes `crates/darner-core/src/logging.rs` (checked against the file list of all 189 open pull requests), and no open or closed issue mentions `DARNER_LOG` being empty. - Replaces or overlaps: none found
A defined but empty filter variable makes `std::env::var` return `Ok("")`, and
`EnvFilter::try_new("")` returns `Ok` with no directive at all: a filter with
no directive enables nothing. A run with `DARNER_LOG=` therefore logged not one
line, at the console or in the file `darner play` names, and never fell back to
`RUST_LOG` as the module doc says it does, nor to the default level.

Treat a present-but-empty value as unset in `resolve_filter`, as every other
environment value in this crate does (`config.rs::env_path`, and
`DARNER_LOG_FILE` in this module), and read `RUST_LOG` even when `DARNER_LOG`
is defined, so the fallback the module documents actually runs. The new test
pins the fallback: an empty `DARNER_LOG` uses `RUST_LOG`, and an empty pair
uses the default level.
First-time contributor

Tested merged onto c8258f95 (release), head 7f51e5ed. RTX 3090 24 GB, driver 621.24, i5-10600K, 32 GB, Windows 11.

One unattended run per build, 60 s in the world after the first frame (DARNER_EXIT_AFTER_WORLD_S=60), with --set DARNER_LOG= (defined but empty):

  • main (c8258f95): the log file has 1 line (the header) and nothing else.
  • this PR: 23,386 lines, the same kind of log as a run without DARNER_LOG.

Both exited with code 0. So the empty value now falls back as described. Not tested: RUST_LOG set at the same time, or a value made only of spaces.

AI-assisted testing (Claude Code, Claude Opus 5.5); results and text reviewed by me.

Tested merged onto `c8258f95` (release), head `7f51e5ed`. RTX 3090 24 GB, driver 621.24, i5-10600K, 32 GB, Windows 11. One unattended run per build, 60 s in the world after the first frame (`DARNER_EXIT_AFTER_WORLD_S=60`), with `--set DARNER_LOG=` (defined but empty): - `main` (`c8258f95`): the log file has 1 line (the header) and nothing else. - this PR: 23,386 lines, the same kind of log as a run without `DARNER_LOG`. Both exited with code 0. So the empty value now falls back as described. Not tested: `RUST_LOG` set at the same time, or a value made only of spaces. _AI-assisted testing (Claude Code, Claude Opus 5.5); results and text reviewed by me._
TrustNo1 changed title from [pr-fix] core: an empty DARNER_LOG means unset, not "log nothing" to core: an empty DARNER_LOG means unset, not "log nothing" 2026-12-06 03:27:00 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'logging-empty-filter:qnjk-logging-empty-filter'
git switch 'qnjk-logging-empty-filter'

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 'qnjk-logging-empty-filter'
git switch 'qnjk-logging-empty-filter'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'qnjk-logging-empty-filter'
git switch 'qnjk-logging-empty-filter'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'qnjk-logging-empty-filter'
git switch 'Main'
git merge --squash 'qnjk-logging-empty-filter'
git switch 'Main'
git merge --ff-only 'qnjk-logging-empty-filter'
git switch 'Main'
git merge 'qnjk-logging-empty-filter'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!572
No description provided.