From 93f106aac2d6411c80a911adac62cd12f80e58be Mon Sep 17 00:00:00 2001 From: historia Date: Sun, 30 Aug 2026 18:49:32 -0400 Subject: feat: output log path when audiobook generation fails --- app/logging_kit.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'app/logging_kit.py') diff --git a/app/logging_kit.py b/app/logging_kit.py index 0fe39c2..8950e6a 100644 --- a/app/logging_kit.py +++ b/app/logging_kit.py @@ -50,17 +50,27 @@ def log_traceback() -> None: RETENTION_DAYS = 30 +def stream_path(prefix: str, log_dir: Path = None) -> Path: + """The ``_YYYYMMDD.log`` stream path, without opening it. + + The one place the stream naming convention is spelled out; callers + point users at the file (e.g. a failure's full details) without + creating or opening it. + """ + directory = log_dir if log_dir is not None else LOG_DIR + return directory / f"{prefix}_{datetime.now():%Y%m%d}.log" + + def day_stream(prefix: str, log_dir: Path = None): """Open today's ``_YYYYMMDD.log`` stream for appending. Returns the open text handle (write through write_line so lines are flushed), or None when the directory/file cannot be opened. """ - directory = log_dir if log_dir is not None else LOG_DIR + path = stream_path(prefix, log_dir) try: - directory.mkdir(parents=True, exist_ok=True) - return (directory / f"{prefix}_{datetime.now():%Y%m%d}.log" - ).open("a", encoding="utf-8") + path.parent.mkdir(parents=True, exist_ok=True) + return path.open("a", encoding="utf-8") except OSError: return None -- cgit v1.2.3