Add logging system: app.log + matching.log with admin viewer
- Backend: RotatingFileHandler for app.log (all) and matching.log (matcher/matching services)
- New GET/DELETE /api/logs/{app|matching} endpoints (admin-only)
- matcher.py: improved cover-download logging (URL, bytes, HTTP errors, missing cover URL)
- Frontend: Logs tab in Admin panel with log switcher, line count selector, color-coded ERROR/WARNING lines, clear button
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import logging.handlers
|
||||
import os
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
@@ -11,14 +12,45 @@ from .config import get_settings
|
||||
from .services.file_watcher import start_file_watcher, stop_file_watcher
|
||||
from .services.podcast_feed import update_all_feeds
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||
|
||||
def _setup_logging():
|
||||
settings = get_settings()
|
||||
os.makedirs(settings.log_dir, exist_ok=True)
|
||||
|
||||
fmt = logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s")
|
||||
|
||||
root = logging.getLogger()
|
||||
root.setLevel(logging.INFO)
|
||||
|
||||
# Console (bestehend)
|
||||
console = logging.StreamHandler()
|
||||
console.setFormatter(fmt)
|
||||
root.addHandler(console)
|
||||
|
||||
# app.log — alle Logs
|
||||
app_fh = logging.handlers.RotatingFileHandler(
|
||||
os.path.join(settings.log_dir, "app.log"),
|
||||
maxBytes=5_000_000, backupCount=2, encoding="utf-8"
|
||||
)
|
||||
app_fh.setFormatter(fmt)
|
||||
root.addHandler(app_fh)
|
||||
|
||||
# matching.log — nur Matching-bezogene Logger
|
||||
match_fh = logging.handlers.RotatingFileHandler(
|
||||
os.path.join(settings.log_dir, "matching.log"),
|
||||
maxBytes=5_000_000, backupCount=2, encoding="utf-8"
|
||||
)
|
||||
match_fh.setFormatter(fmt)
|
||||
for name in ("app.services.matcher", "app.services.matching"):
|
||||
logging.getLogger(name).addHandler(match_fh)
|
||||
|
||||
|
||||
_setup_logging()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_scheduler = AsyncIOScheduler()
|
||||
|
||||
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
settings = get_settings()
|
||||
@@ -28,7 +60,6 @@ async def lifespan(app: FastAPI):
|
||||
await init_db()
|
||||
await start_file_watcher()
|
||||
|
||||
# Podcast-Feed-Scheduler
|
||||
_scheduler.add_job(update_all_feeds, "interval", hours=settings.podcast_update_interval_hours, id="feed_update")
|
||||
_scheduler.start()
|
||||
|
||||
@@ -55,7 +86,7 @@ if os.path.exists(settings.covers_dir):
|
||||
app.mount("/covers", StaticFiles(directory=settings.covers_dir), name="covers")
|
||||
|
||||
from .routers import auth, libraries, items, stream, me, users, settings as settings_router
|
||||
from .routers import matching, podcasts, setup, filebrowser
|
||||
from .routers import matching, podcasts, setup, filebrowser, logs
|
||||
|
||||
app.include_router(setup.router)
|
||||
app.include_router(auth.router)
|
||||
@@ -68,3 +99,4 @@ app.include_router(settings_router.router)
|
||||
app.include_router(matching.router)
|
||||
app.include_router(podcasts.router)
|
||||
app.include_router(filebrowser.router)
|
||||
app.include_router(logs.router)
|
||||
|
||||
Reference in New Issue
Block a user