Add live logs to admin dashboard with level filtering and error middleware
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
import logging
|
||||
import traceback
|
||||
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from app.core.config import settings
|
||||
from app.api.endpoints import admin, auth, bandcamp, billing, lastfm, manual_import, playlist_fix, playlists, profile, recommendations, youtube_music
|
||||
@@ -27,6 +31,21 @@ app.include_router(bandcamp.router, prefix="/api")
|
||||
app.include_router(profile.router, prefix="/api")
|
||||
|
||||
|
||||
logger = logging.getLogger("app")
|
||||
|
||||
|
||||
@app.middleware("http")
|
||||
async def log_errors(request: Request, call_next):
|
||||
try:
|
||||
response = await call_next(request)
|
||||
if response.status_code >= 400:
|
||||
logger.warning(f"{request.method} {request.url.path} -> {response.status_code}")
|
||||
return response
|
||||
except Exception as e:
|
||||
logger.error(f"{request.method} {request.url.path} -> 500: {e}\n{traceback.format_exc()}")
|
||||
return JSONResponse(status_code=500, content={"detail": "Internal server error"})
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
async def health():
|
||||
return {"status": "ok", "app": "vynl"}
|
||||
|
||||
Reference in New Issue
Block a user