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

Open
Sidlik900 wants to merge 2 commits from upstream-pr/2227 into main
Sidlik900 commented 2026-11-25 08:23:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sidlik900 on 2026-11-25T08:23:26Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6600284797 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2227). Originally posted by [Sidlik900](https://github.com/Sidlik900) on 2026-11-25T08:23:26Z. --- 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.
catminou4 commented 2026-11-25 09:05:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T08:48:15Z.

Review: APPROVED


VICTORY_LOG_FILE + terminal-only stderr in victory-core. Tested locally: merged into main 940d32f69b, cargo test -p victory-core --locked on macOS arm64 — 19 passed, 0 failed. Approving.

<!-- greyfinch-sync:Marvisak/VIctory:review:6054377464 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2227#pullrequestreview-6054377464). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T08:48:15Z. **Review:** APPROVED --- VICTORY_LOG_FILE + terminal-only stderr in victory-core. Tested locally: merged into main 940d32f69b, `cargo test -p victory-core --locked` on macOS arm64 — 19 passed, 0 failed. Approving.
Dathinel commented 2026-11-25 09:06:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T08:41:24Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7157348818 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2227#issuecomment-7157348818). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T08:41:24Z. --- 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.
Sidlik900 commented 2026-11-25 10:07:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Sidlik900 on 2026-11-25T09:51:40Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158898600 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2227#issuecomment-7158898600). Originally posted by [Sidlik900](https://github.com/Sidlik900) on 2026-11-25T09:51:40Z. --- 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.
Marvisak commented 2026-11-25 14:07:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T13:30:25Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163875181 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2227#issuecomment-7163875181). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T13:30:25Z. --- <!-- 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 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/2227:upstream-pr/2227'
git switch 'upstream-pr/2227'

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/2227'
git switch 'upstream-pr/2227'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2227'
git switch 'upstream-pr/2227'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2227'
git switch 'main'
git merge --squash 'upstream-pr/2227'
git switch 'main'
git merge --ff-only 'upstream-pr/2227'
git switch 'main'
git merge 'upstream-pr/2227'
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!2225
No description provided.