From 0cb5a73e61fd569f81d292afd1d13c6d34e4e34d Mon Sep 17 00:00:00 2001 From: James Westbrook <0xthresh@protonmail.com> Date: Sun, 29 Mar 2026 12:47:20 -0600 Subject: [PATCH] fix: logging updates to prevent silent errors --- Dockerfile | 2 ++ terminals/logging.py | 4 +++- terminals/main.py | 7 ++++--- terminals/migrations/env.py | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 43cd095..cd77a6e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.12-slim +ENV PYTHONUNBUFFERED=1 + WORKDIR /app COPY . . diff --git a/terminals/logging.py b/terminals/logging.py index 048084a..397c9e8 100644 --- a/terminals/logging.py +++ b/terminals/logging.py @@ -46,4 +46,6 @@ def setup_logging() -> None: # Intercept stdlib logging (uvicorn, sqlalchemy, etc.). logging.basicConfig(handlers=[_InterceptHandler()], level=0, force=True) for name in ("uvicorn", "uvicorn.error", "uvicorn.access", "sqlalchemy"): - logging.getLogger(name).handlers = [_InterceptHandler()] + named = logging.getLogger(name) + named.handlers = [_InterceptHandler()] + named.propagate = False diff --git a/terminals/main.py b/terminals/main.py index 06f8308..2a70a7f 100644 --- a/terminals/main.py +++ b/terminals/main.py @@ -17,11 +17,12 @@ from terminals.routers.proxy import close_proxy_client, router as proxy_router @asynccontextmanager async def lifespan(app: FastAPI): """Startup / shutdown lifecycle.""" - setup_logging() - - # Run DB migrations + # Run DB migrations first (alembic's fileConfig reconfigures logging). init_db() + # Set up loguru AFTER alembic so our InterceptHandler isn't overwritten. + setup_logging() + app.state.backend = create_backend() # Recover state from any running containers (survives process restart). diff --git a/terminals/migrations/env.py b/terminals/migrations/env.py index 0bbabd3..0228dd2 100644 --- a/terminals/migrations/env.py +++ b/terminals/migrations/env.py @@ -23,7 +23,7 @@ config = context.config # Set up Python logging from the INI file. if config.config_file_name is not None: - fileConfig(config.config_file_name) + fileConfig(config.config_file_name, disable_existing_loggers=False) # Target metadata for autogenerate support. target_metadata = Base.metadata