core: add VICTORY_LOG_FILE and terminal-only stderr colour #2227

Open
github-bot wants to merge 2 commits from github-bot/gh-2227 into main AGit
Owner

@⁠Sidlik900 on GitHub · 2026-11-25 08:23 UTC · original
Sidlik900:core/victory-log-file → main · +474 −23 · 7 files · 2 commits · open

Follows up on the released VICTORY_LOG_FILE task in #1633.

Summary

  • Add VICTORY_LOG_FILE=<file> support in crates/victory-core/src/logging.rs to mirror logs as plain, unwrapped UTF-8 lines without ANSI escape sequences (creating missing parent directories and warning on open failure without panicking).
  • Emit ANSI colour codes on stderr only when connected to a terminal (IsTerminal), honouring NO_COLOR and CLICOLOR_FORCE.
  • Document VICTORY_LOG_FILE, NO_COLOR, and CLICOLOR_FORCE in README.md.
  • Add unit and concurrency tests in victory-core (no game files required).

Verification

  • cargo xtask policy
  • cargo test -p victory-core --locked (19 passed)
  • cargo test -p victory-core --all-features --locked (19 passed)
  • cargo test -p xtask -p victory --locked (all passed)
  • cargo clippy --workspace --all-targets --locked -- -D warnings
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings

AI-assisted (Antigravity); synthetic unit tests only, no game data.

**@⁠Sidlik900** on GitHub · 2026-11-25 08:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2227) `Sidlik900:core/victory-log-file` → `main` · +474 −23 · 7 files · 2 commits · open Follows up on the released `VICTORY_LOG_FILE` task in #1633. ### Summary - Add `VICTORY_LOG_FILE=<file>` support in `crates/victory-core/src/logging.rs` to mirror logs as plain, unwrapped UTF-8 lines without ANSI escape sequences (creating missing parent directories and warning on open failure without panicking). - Emit ANSI colour codes on `stderr` only when connected to a terminal (`IsTerminal`), honouring `NO_COLOR` and `CLICOLOR_FORCE`. - Document `VICTORY_LOG_FILE`, `NO_COLOR`, and `CLICOLOR_FORCE` in `README.md`. - Add unit and concurrency tests in `victory-core` (no game files required). ### Verification - `cargo xtask policy` - `cargo test -p victory-core --locked` (19 passed) - `cargo test -p victory-core --all-features --locked` (19 passed) - `cargo test -p xtask -p victory --locked` (all passed) - `cargo clippy --workspace --all-targets --locked -- -D warnings` - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` AI-assisted (Antigravity); synthetic unit tests only, no game data.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:59:04 +00:00
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 08:41 UTC · original

The audio recorder child can truncate the parent’s log. On e25d2ae, main initializes logging before checking capture::child(), and capture::start() spawns current_exe() with the parent environment. Consequently both processes call File::create on the same VICTORY_LOG_FILE.

I reproduced the logging path on Windows with VICTORY_LOG=info: initialize in a parent, log BEFORE, spawn and wait for a child that initializes and logs CHILD, then log AFTER. Redirected stderr contained all three markers. The file contained CHILD, eight NUL bytes, then AFTER; BEFORE was gone. Running the parent without spawning preserved both parent lines. This used the public logging initializer and synthetic messages, without starting audio capture.

Could the recorder inherit a separate destination or skip the mirror if only the parent should own the per-run file? A two-process regression would cover this separately from the existing thread test. AI-assisted validation.

**@⁠Dathinel** on GitHub · 2026-11-25 08:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2227#issuecomment-7157348818) The audio recorder child can truncate the parent’s log. On e25d2ae, main initializes logging before checking capture::child(), and capture::start() spawns current_exe() with the parent environment. Consequently both processes call File::create on the same VICTORY_LOG_FILE. I reproduced the logging path on Windows with VICTORY_LOG=info: initialize in a parent, log BEFORE, spawn and wait for a child that initializes and logs CHILD, then log AFTER. Redirected stderr contained all three markers. The file contained CHILD, eight NUL bytes, then AFTER; BEFORE was gone. Running the parent without spawning preserved both parent lines. This used the public logging initializer and synthetic messages, without starting audio capture. Could the recorder inherit a separate destination or skip the mirror if only the parent should own the per-run file? A two-process regression would cover this separately from the existing thread test. AI-assisted validation.
Author
Owner

@⁠Sidlik900 on GitHub · 2026-11-25 09:51 UTC · original

Good catch, @⁠Dathinel — thank you for reproducing and explaining that clearly. Fixed in 5aebbc4 so only the parent process owns VICTORY_LOG_FILE:

Changes

  • Added victory_core::logging::init_stderr_only (crates/victory-core/src/logging.rs) so helper children log to stderr without opening or truncating VICTORY_LOG_FILE.
  • Updated crates/victory-hle/src/modules/audio/capture.rs (recorder_command strips VICTORY_LOG_FILE from the child environment; added capture::is_child()) and apps/victory/src/main.rs (checks capture::is_child() before logging::init and calls init_stderr_only("info") for the recorder child).
  • Added two-process / helper-child regression tests:
    • logging::tests::two_process_stderr_only_child_preserves_parent_log_file in crates/victory-core/src/logging.rs (parent logs BEFORE, spawns child with init_stderr_only logging CHILD, logs AFTER; checks all three on stderr and exact intact 2-line parent log file with no NUL bytes).
    • modules::audio::capture::tests::recorder_command_clears_log_file_env in crates/victory-hle/src/modules/audio/capture.rs.
    • audio_capture_child_does_not_truncate_parent_log_file in apps/victory/tests/logging.rs (#[cfg(all(windows, feature = "diagnostics"))]: spawns the victory binary with VICTORY_AUDIO_CAPTURE + VICTORY_AUDIO_CAPTURE_OF=0 between parent BEFORE/AFTER logs and verifies parent log integrity and child stderr output).

Verification (5aebbc4)

  • rustfmt --edition 2024 --check crates/victory-core/src/logging.rs apps/victory/src/main.rs apps/victory/tests/logging.rs (passed)
  • cargo xtask policy (asset policy: 183 files ok)
  • cargo test -p victory-core -p victory -p xtask --locked (victory-core: 20 passed, victory: 10 + 2 passed, xtask: 6 passed)
  • cargo test -p victory-core -p victory -p xtask --all-features --locked (victory-core: 20 passed, victory: 10 + 2 + 1 logging passed, xtask: 6 passed)
  • cargo test -p victory-hle --all-features --locked capture (1 passed)
  • cargo clippy --workspace --all-targets --locked -- -D warnings & --all-features (both passed)

AI-assisted (Antigravity); synthetic tests only, no game data.

**@⁠Sidlik900** on GitHub · 2026-11-25 09:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2227#issuecomment-7158898600) Good catch, @⁠Dathinel — thank you for reproducing and explaining that clearly. Fixed in 5aebbc4 so only the parent process owns `VICTORY_LOG_FILE`: ### Changes - Added `victory_core::logging::init_stderr_only` (`crates/victory-core/src/logging.rs`) so helper children log to stderr without opening or truncating `VICTORY_LOG_FILE`. - Updated `crates/victory-hle/src/modules/audio/capture.rs` (`recorder_command` strips `VICTORY_LOG_FILE` from the child environment; added `capture::is_child()`) and `apps/victory/src/main.rs` (checks `capture::is_child()` before `logging::init` and calls `init_stderr_only("info")` for the recorder child). - Added two-process / helper-child regression tests: - `logging::tests::two_process_stderr_only_child_preserves_parent_log_file` in `crates/victory-core/src/logging.rs` (parent logs `BEFORE`, spawns child with `init_stderr_only` logging `CHILD`, logs `AFTER`; checks all three on stderr and exact intact 2-line parent log file with no NUL bytes). - `modules::audio::capture::tests::recorder_command_clears_log_file_env` in `crates/victory-hle/src/modules/audio/capture.rs`. - `audio_capture_child_does_not_truncate_parent_log_file` in `apps/victory/tests/logging.rs` (`#[cfg(all(windows, feature = "diagnostics"))]`: spawns the `victory` binary with `VICTORY_AUDIO_CAPTURE` + `VICTORY_AUDIO_CAPTURE_OF=0` between parent `BEFORE`/`AFTER` logs and verifies parent log integrity and child stderr output). ### Verification (`5aebbc4`) - `rustfmt --edition 2024 --check crates/victory-core/src/logging.rs apps/victory/src/main.rs apps/victory/tests/logging.rs` (passed) - `cargo xtask policy` (`asset policy: 183 files ok`) - `cargo test -p victory-core -p victory -p xtask --locked` (`victory-core`: 20 passed, `victory`: 10 + 2 passed, `xtask`: 6 passed) - `cargo test -p victory-core -p victory -p xtask --all-features --locked` (`victory-core`: 20 passed, `victory`: 10 + 2 + 1 `logging` passed, `xtask`: 6 passed) - `cargo test -p victory-hle --all-features --locked capture` (1 passed) - `cargo clippy --workspace --all-targets --locked -- -D warnings` & `--all-features` (both passed) AI-assisted (Antigravity); synthetic tests only, no game data.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:30 UTC · original

Automated triage for the maintainers.

The PR adds VICTORY_LOG_FILE (a plain-text copy of the log) and colour on stderr only when it is a terminal (crates/victory-core/src/logging.rs). It also keeps the audio recorder child from opening the file: capture.rs recorder_command strips the variable, and main.rs calls init_stderr_only for the child. The follow-up commit answers the truncation report from a reviewer.

This needs the maintainer's decision. It changes dependencies (tracing added to victory-core/Cargo.toml, and Cargo.lock), and it changes how the program spawns its helper process. Its tests also spawn processes (apps/victory/tests/logging.rs, the two-process test in logging.rs). No CI run is recorded for this head, so build and test status here is unknown. Smaller point: logging.rs grows by about 350 lines for a log-file option, so a leaner version would be easier to review.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2227#issuecomment-7163875181) <!-- victory-triage v1 head=5aebbc493b7c30cd3eb6e7f32e841358f16a0930 verdict=needs-work at=2026-11-25T13:31:30Z --> Automated triage for the maintainers. The PR adds `VICTORY_LOG_FILE` (a plain-text copy of the log) and colour on stderr only when it is a terminal (`crates/victory-core/src/logging.rs`). It also keeps the audio recorder child from opening the file: `capture.rs` `recorder_command` strips the variable, and `main.rs` calls `init_stderr_only` for the child. The follow-up commit answers the truncation report from a reviewer. This needs the maintainer's decision. It changes dependencies (`tracing` added to `victory-core/Cargo.toml`, and `Cargo.lock`), and it changes how the program spawns its helper process. Its tests also spawn processes (`apps/victory/tests/logging.rs`, the two-process test in `logging.rs`). No CI run is recorded for this head, so build and test status here is unknown. Smaller point: `logging.rs` grows by about 350 lines for a log-file option, so a leaner version would be easier to review. --- _Generated by [Claude Code](https://claude.ai/code)_
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 origin '+refs/pull/2227/head:github-bot/gh-2227'
git switch 'github-bot/gh-2227'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2227'
git switch 'github-bot/gh-2227'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2227'
git switch 'github-bot/gh-2227'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2227'
git switch 'main'
git merge --squash 'github-bot/gh-2227'
git switch 'main'
git merge --ff-only 'github-bot/gh-2227'
git switch 'main'
git merge 'github-bot/gh-2227'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2227
No description provided.