Skip to content

feat(logging): rotating file log + level control; stop leaking exceptions into the UI - #295

Merged
thcp merged 1 commit into
mainfrom
feat/rotating-file-logs
Jul 16, 2026
Merged

feat(logging): rotating file log + level control; stop leaking exceptions into the UI#295
thcp merged 1 commit into
mainfrom
feat/rotating-file-logs

Conversation

@thcp

@thcp thcp commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Closes #291, closes #292, closes #283. First PR of Phase 1 (#272) — plan in #272 (comment) (PR-1A).

What

  • New app/core/logging_setup.py — attaches a RotatingFileHandler to the stemdeck logger: LOGS_DIR/stemdeck.log, 5 MB × 3 backups, UTF-8, timestamped one-char-level format. delay=True so nothing is touched until the first record, and a read-only FS degrades to stdout-only logging instead of failing startup. Idempotence guard so uvicorn --reload re-imports don't stack handlers. Propagation stays on — stdout behavior is unchanged, the file is additive (Server mode writes no log file at all #291).
  • Level controlSTEMDECK_LOG_LEVEL=DEBUG|INFO|WARNING (default INFO), STEMDECK_DEBUG=1 shorthand. The analyze diagnostics (chroma:, key candidates:) are logger.debug and could never emit under the previous hardcoded INFO level, despite the main.py comment claiming they showed — comment fixed, diagnostics now reachable (The analyze diagnostics are dead code at INFO level #292).
  • Stage-message leakanalyze.py no longer interpolates the raw exception repr into the user-visible "Analysis skipped (…)" stage line; the traceback was already logger.exception'd (Internal exception text leaks into the UI stage line #283).

Testing

  • New tests/test_logging_setup.py: file created on first record, rotation bound honored, idempotence, env level resolution (incl. bogus value fallback + DEBUG shorthand precedence), unwritable LOGS_DIR degrades without raising.
  • Full suite: 158 passed. ruff check + ruff format --check clean.

…ions into the UI

Attach a RotatingFileHandler (LOGS_DIR/stemdeck.log, 5 MB x 3, timestamped)
to the stemdeck logger so server and Docker deployments keep an on-disk
trail -- until now LOGS_DIR existed but nothing ever wrote to it, and
stdout scrollback was the only record. Best-effort: a read-only FS
degrades to stdout-only logging instead of failing startup.

Level is now controllable: STEMDECK_LOG_LEVEL=DEBUG|INFO|WARNING, with
STEMDECK_DEBUG=1 as shorthand. This also un-deadens the analyze
diagnostics ("chroma:", "key candidates:") -- they are logger.debug
calls that could never emit under the previous hardcoded INFO level,
despite the comment claiming otherwise.

Also stop interpolating raw exception reprs into the user-visible
"Analysis skipped" stage message; the traceback is already in the log.

Closes #291
Closes #292
Closes #283
@thcp
thcp merged commit 995e402 into main Jul 16, 2026
8 checks passed
@thcp
thcp deleted the feat/rotating-file-logs branch July 16, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The analyze diagnostics are dead code at INFO level Server mode writes no log file at all Internal exception text leaks into the UI stage line

1 participant