Add logging configuration and middleware for improved request tracking

This commit is contained in:
JSC
2025-07-25 10:54:30 +02:00
parent 2860008a6d
commit b6d1ef2a27
7 changed files with 137 additions and 4 deletions

View File

@@ -4,20 +4,36 @@ from contextlib import asynccontextmanager
from fastapi import FastAPI
from app.core.database import init_db
from app.core.logging import get_logger, setup_logging
from app.middleware.logging import LoggingMiddleware
@asynccontextmanager
async def lifespan(_app: FastAPI) -> AsyncGenerator[None, None]:
"""Application lifespan context manager for setup and teardown."""
setup_logging()
logger = get_logger(__name__)
logger.info("Starting application")
await init_db()
logger.info("Database initialized")
yield
logger.info("Shutting down application")
def create_app() -> FastAPI:
"""Create and configure the FastAPI application."""
app = FastAPI(lifespan=lifespan)
app.add_middleware(LoggingMiddleware)
logger = get_logger(__name__)
@app.get("/")
def health() -> dict[str, str]:
logger.info("Health check endpoint accessed")
return {"status": "healthy"}
return app