diff options
| author | historia <historiavg@proton.me> | 2026-08-28 13:51:01 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-28 13:51:01 -0400 |
| commit | afb2c2d5b297c5aa28bcced0e3f90e207d799c2a (patch) | |
| tree | 80e6c336736a7c441160db8f52c9e3403497610a /app/logging_kit.py | |
| parent | 5ed31309b6d0db94ccd566914653d367f4577c64 (diff) | |
| download | tts-audiobook-generator-afb2c2d5b297c5aa28bcced0e3f90e207d799c2a.tar.gz | |
fix: remove backtrace from console output when using incorrect/incomplete cli flags
Diffstat (limited to 'app/logging_kit.py')
| -rw-r--r-- | app/logging_kit.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/app/logging_kit.py b/app/logging_kit.py index c16b7ed..0fe39c2 100644 --- a/app/logging_kit.py +++ b/app/logging_kit.py @@ -18,13 +18,33 @@ Everything here is stdlib-only and best-effort: logging must never break the app, so an unwritable directory or a failed write degrades to a no-op. """ +import logging import time +import traceback from datetime import datetime from pathlib import Path # The single log directory (app/logs, already gitignored). LOG_DIR = Path(__file__).resolve().parent / "logs" +# Reserved logger for file-only traceback dumps: records emitted on this +# name reach the dated log file through the root handlers, while the +# converter's console filter (setup_logging's _console_log_filter) drops +# them, so a handled failure can keep its full traceback out of the +# console without losing it from the logs. +TRACEBACK_LOGGER = "app.traceback" + + +def log_traceback() -> None: + """Log the active exception's traceback to the log file only. + + Call from inside an ``except`` block: the record reaches the file + handler but not the console, where the caller shows a single friendly + message instead (tracebacks are for the logs, or for real crashes). + """ + logging.getLogger(TRACEBACK_LOGGER).error(traceback.format_exc()) + + # Stream/artifact files older than this are deleted by prune_logs (called # once per app start). Server logs and pid files are never touched. RETENTION_DAYS = 30 |
