From afb2c2d5b297c5aa28bcced0e3f90e207d799c2a Mon Sep 17 00:00:00 2001 From: historia Date: Fri, 28 Aug 2026 13:51:01 -0400 Subject: fix: remove backtrace from console output when using incorrect/incomplete cli flags --- app/logging_kit.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'app/logging_kit.py') 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 -- cgit v1.2.3