aboutsummaryrefslogtreecommitdiff
path: root/app/ui/hub.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-08-28 03:16:14 -0400
committerhistoria <historiavg@proton.me>2026-08-28 03:16:14 -0400
commitd487996281f71ccd3034dd708fa099057e528b42 (patch)
tree989d9f40f5c2dbb03e1cf570f2c463f43cf5ac76 /app/ui/hub.py
parent5c3db8f500ff206f3a675d8f4184cb0d61f94804 (diff)
downloadtts-audiobook-generator-d487996281f71ccd3034dd708fa099057e528b42.tar.gz
feat: unified logging with logging_kit.py
Diffstat (limited to 'app/ui/hub.py')
-rw-r--r--app/ui/hub.py54
1 files changed, 10 insertions, 44 deletions
diff --git a/app/ui/hub.py b/app/ui/hub.py
index a5c3dc4..e17e862 100644
--- a/app/ui/hub.py
+++ b/app/ui/hub.py
@@ -30,6 +30,8 @@ from datetime import datetime
from pathlib import Path
from typing import Callable, Optional, Tuple
+import logging_kit
+
from backends import (
REGISTRY,
BackendStatus,
@@ -561,60 +563,24 @@ class _Hub:
return tui.Wizard.BACK
-class _TeeWriter:
- """A file-like that mirrors writes to a log file and an inner stream.
-
- Used to capture the server module's plain-console output (the task view
- already redirects stdout to its line-writer) into a persistent log file
- under ``servers.LOG_DIR`` without losing the on-screen log tail.
- """
-
- def __init__(self, logf, inner):
- self._logf = logf
- self._inner = inner
-
- def write(self, text):
- if not text:
- return 0
- try:
- self._logf.write(text)
- except OSError:
- pass
- try:
- self._inner.write(text)
- except OSError:
- pass
- return len(text)
-
- def flush(self):
- try:
- self._logf.flush()
- except OSError:
- pass
- try:
- self._inner.flush()
- except OSError:
- pass
-
-
def _server_action_step(spec, action: str):
"""Build a task step that starts/stops SPEC's server, logged to a file.
ACTION is "start" or "stop". The step runs inside the task view (no
- console drop): the server module's output is tee'd to
- ``<servers.LOG_DIR>/<name>-<action>.log`` and to the view's log tail.
- Returns ``(TaskStep, log_path)`` so the caller can point the user at the
- file on failure.
+ console drop): the server module's output is tee'd to a timestamped
+ ``<name>_<action>_*.log`` artifact under ``servers.LOG_DIR`` (see
+ ``logging_kit.run_artifact``) and to the view's log tail. Returns
+ ``(TaskStep, log_path)`` so the caller can point the user at the file
+ on failure.
"""
- log_path = servers.LOG_DIR / f"{spec.name}-{action}.log"
title = (f"Start {spec.name} server" if action == "start"
else f"Stop {spec.name} server")
+ log_path, logf = logging_kit.run_artifact(f"{spec.name}_{action}",
+ log_dir=servers.LOG_DIR)
def work(emit, cancel):
- servers.LOG_DIR.mkdir(parents=True, exist_ok=True)
inner = sys.stdout # the task view's line-writer, when run in TUI
- with log_path.open("w", encoding="utf-8") as logf, \
- contextlib.redirect_stdout(_TeeWriter(logf, inner)):
+ with contextlib.redirect_stdout(logging_kit.TeeWriter(logf, inner)):
if action == "start":
ok = servers.start(spec, cancel=cancel)
else: