feat(backend): daily request-tagged log files + print job lifecycle logging
Platform v2 step 0.4 (APPS_PLATFORM §10). New core/logging.py: - root logger -> stderr + <db dir>/logs/xenia-YYYY-MM-DD.log (UTC date, /app/data/logs in Docker, $LOG_DIR overrides); files older than the system.log_retention_days setting (default 30) are pruned - line format: UTC ISO time, level, logger, [req= user= device=], message - RequestContextMiddleware (pure ASGI): request id per request, X-Request-ID response header, one http line per request (DEBUG for plain reads) - auth tags the user via set_log_context; uvicorn loggers routed through ours Print jobs now log created / attempt / success / failed / abandoned with the job id, so a missing ticket can be traced. Removed cloud_sync's basicConfig. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+18
-3
@@ -1,10 +1,18 @@
|
||||
import os
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from database import engine, Base
|
||||
from core.logging import setup_logging, apply_retention_setting, RequestContextMiddleware
|
||||
|
||||
# First thing: every logger below (and uvicorn's) writes through these handlers.
|
||||
setup_logging()
|
||||
logger = logging.getLogger("xenia.main")
|
||||
|
||||
from config import settings
|
||||
from database import engine, Base, SessionLocal
|
||||
from middleware.license_check import LicenseCheckMiddleware
|
||||
from services.cloud_sync import start_cloud_sync
|
||||
|
||||
@@ -771,14 +779,19 @@ async def lifespan(app: FastAPI):
|
||||
ws_init_loop(loop)
|
||||
Base.metadata.create_all(bind=engine)
|
||||
_run_migrations()
|
||||
_db = SessionLocal()
|
||||
try:
|
||||
apply_retention_setting(_db)
|
||||
finally:
|
||||
_db.close()
|
||||
logger.info("startup version=%s", settings.VERSION)
|
||||
# Before the app reports healthy: the proxy's :8443 needs these files to start
|
||||
from services.tls_identity import ensure_tls_identity
|
||||
ensure_tls_identity()
|
||||
start_print_retry_thread()
|
||||
pruned = prune_old_events(hours=24)
|
||||
if pruned:
|
||||
import logging
|
||||
logging.getLogger(__name__).info("ws_bus: pruned %d old sync_events", pruned)
|
||||
logger.info("ws_bus: pruned %d old sync_events", pruned)
|
||||
_init_chat()
|
||||
sync_task = await start_cloud_sync()
|
||||
reservation_task = await start_reservation_tasks()
|
||||
@@ -796,6 +809,8 @@ app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
)
|
||||
app.add_middleware(LicenseCheckMiddleware)
|
||||
# Added last = outermost: the request id exists before any other middleware runs.
|
||||
app.add_middleware(RequestContextMiddleware)
|
||||
|
||||
# Serve product images as static files
|
||||
IMAGE_DIR = "/app/data/product_images"
|
||||
|
||||
Reference in New Issue
Block a user