Add structured logging throughout the backend
Request-level logging middleware (method/path/status/duration), per-module loggers in routes/services (nearby search radius expansion, 404s, name search), LOG_LEVEL setting wired through docker-compose, and seed_loader converted from print() to logging. Verified: pytest passes, and manually confirmed log lines appear for both successful and 404 requests via `docker compose logs api`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
188bf01d6e
commit
be67902b45
11 changed files with 114 additions and 4 deletions
|
|
@ -1,9 +1,26 @@
|
|||
import logging
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from app.api.routes import cities, health, nearby, places
|
||||
from app.config import settings
|
||||
from app.core.logging import configure_logging, log_requests
|
||||
|
||||
app = FastAPI(title="guideCity API", version="0.1.0")
|
||||
configure_logging(level=getattr(logging, settings.log_level.upper(), logging.INFO))
|
||||
logger = logging.getLogger("guidecity")
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(_app: FastAPI) -> AsyncIterator[None]:
|
||||
logger.info("guideCity API startup complete (log_level=%s)", settings.log_level)
|
||||
yield
|
||||
logger.info("guideCity API shutting down")
|
||||
|
||||
|
||||
app = FastAPI(title="guideCity API", version="0.1.0", lifespan=lifespan)
|
||||
app.middleware("http")(log_requests)
|
||||
|
||||
app.include_router(health.router, prefix=settings.api_v1_prefix)
|
||||
app.include_router(cities.router, prefix=settings.api_v1_prefix)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue