From d487996281f71ccd3034dd708fa099057e528b42 Mon Sep 17 00:00:00 2001 From: historia Date: Fri, 28 Aug 2026 03:16:14 -0400 Subject: feat: unified logging with logging_kit.py --- app/ui/hub.py | 54 ++++++++++-------------------------------------------- 1 file changed, 10 insertions(+), 44 deletions(-) (limited to 'app/ui/hub.py') 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 - ``/-.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 + ``__*.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: -- cgit v1.2.3