Refactor: Zentrales Logging + robuste Token-Erfassung (Phase 2)
- app.py: logging.basicConfig (MC_LOG_LEVEL, INFO default) als eine Konfiguration für alle Module. - Neuer services/gateway_stream.py: SSE-/Non-Stream-usage-Parsing aus dem gateway_proxy-Router extrahiert; robuster Zeilenparser mit Debug-Logging statt verschluckter Exceptions. Router ist jetzt dünn. - token_stats.py: In-Memory-Cache + gedrosseltes Flushen (5s) + atexit-Flush statt Write-pro-Request; atomarer Write (.tmp -> replace); thread-safe. - agent.py/discover.py: stille `except Exception: pass` durch gezieltes log.debug/warning ersetzt; ungenutzten yaml-Import entfernt. Verifiziert: Stream-Parsing (Summen + per-Modell), malformed-Chunk übersteht, flush schreibt; app importiert sauber. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,9 @@ setzt eine no-cache-Middleware. Im Dev läuft das Frontend über den Vite-Dev-
|
||||
Server (proxyt /api hierher), daher CORS für localhost offen.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import FileResponse
|
||||
@@ -15,6 +18,13 @@ from starlette.requests import Request
|
||||
from config import FRONTEND_DIST, VERSION
|
||||
from routers import agent, connect, gateway_proxy, health, maintenance, memory, models, routing, system
|
||||
|
||||
# Zentrales Logging — Level via MC_LOG_LEVEL (INFO default). Eine Konfiguration
|
||||
# für alle Module (logging.getLogger(__name__)).
|
||||
logging.basicConfig(
|
||||
level=os.environ.get("MC_LOG_LEVEL", "INFO").upper(),
|
||||
format="%(asctime)s %(levelname)-7s %(name)s: %(message)s",
|
||||
)
|
||||
|
||||
app = FastAPI(title="Mission Control 2.0", version=VERSION)
|
||||
|
||||
# Dev: Vite-Dev-Server (5173) ruft das Backend per /api auf.
|
||||
|
||||
Reference in New Issue
Block a user