From 60fa791213ce1bffd3d06c53879d4f36b221e356 Mon Sep 17 00:00:00 2001 From: Kaiohz Date: Wed, 6 May 2026 16:55:41 +0200 Subject: [PATCH 1/2] feat(api): initialize FastAPI with uvicorn logging and CORS middleware Configure uvicorn access log integration, add CORS middleware setup, and implement health check endpoint with proper logging configuration. Set default log level to INFO and prepare alembic migration runner utility. --- src/main.py | 48 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/src/main.py b/src/main.py index 9237afe..008e0af 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,16 @@ -"""Main entry point for the RAGAnything API.""" - +import asyncio import logging -import logging.config +import sys from contextlib import asynccontextmanager from pathlib import Path -import uvicorn +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", + stream=sys.stdout, + force=True, +) + from alembic.config import Config from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware @@ -22,41 +27,8 @@ from application.api.query_routes import query_router from dependencies import app_config, bm25_adapter, classical_vector_store -_LOG_FORMAT = "%(asctime)s %(levelname)-8s [%(name)s] %(message)s" - -LOG_CONFIG = { - "version": 1, - "disable_existing_loggers": False, - "formatters": { - "standard": {"format": _LOG_FORMAT}, - }, - "handlers": { - "console": { - "class": "logging.StreamHandler", - "formatter": "standard", - "stream": "ext://sys.stderr", - }, - }, - "loggers": { - "uvicorn": {"handlers": ["console"], "level": "INFO", "propagate": False}, - "uvicorn.error": {"handlers": ["console"], "level": "INFO", "propagate": False}, - "uvicorn.access": { - "handlers": ["console"], - "level": "INFO", - "propagate": False, - }, - }, - "root": { - "level": "INFO", - "handlers": ["console"], - }, -} - -logging.config.dictConfig(LOG_CONFIG) - logger = logging.getLogger(__name__) - def _run_alembic_upgrade() -> None: """Run Alembic migrations to head.""" alembic_dir = Path(__file__).parent @@ -138,7 +110,7 @@ def run_fastapi(): host=app_config.HOST, port=app_config.PORT, log_level=app_config.UVICORN_LOG_LEVEL, - log_config=LOG_CONFIG, + log_config=None, access_log=True, ws="none", ) From e8a477e1bec0778400207464f4d03f2e4fabfe59 Mon Sep 17 00:00:00 2001 From: Kaiohz Date: Wed, 6 May 2026 18:47:18 +0200 Subject: [PATCH 2/2] Add uvicorn import to main.py --- src/main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.py b/src/main.py index 008e0af..0b276aa 100644 --- a/src/main.py +++ b/src/main.py @@ -4,6 +4,8 @@ from contextlib import asynccontextmanager from pathlib import Path +import uvicorn + logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",