add logger for more strucutred logging in python
This commit is contained in:
parent
1f04753250
commit
8c65aa0916
2 changed files with 52 additions and 9 deletions
|
|
@ -15,6 +15,7 @@ from api.worker import (
|
|||
)
|
||||
from fastapi import Depends, FastAPI, HTTPException, Query
|
||||
from api.auth import User
|
||||
from logger import get_logger
|
||||
from models.listing import QueryParameters
|
||||
from repositories.listing_repository import ListingRepository
|
||||
from repositories.listing_repository import ListingRepository
|
||||
|
|
@ -25,15 +26,17 @@ from alembic import command
|
|||
from alembic.config import Config
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
alembic_cfg = Config("./alembic.ini")
|
||||
print("Running alembic migrations")
|
||||
logger.info("Running alembic migrations")
|
||||
command.upgrade(alembic_cfg, "head")
|
||||
print("Finished running alembic migrations")
|
||||
logger.info("Finished running alembic migrations")
|
||||
yield
|
||||
print("Shutting down")
|
||||
logger.warning("Shutting down")
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
|
@ -55,6 +58,7 @@ app.add_middleware(
|
|||
async def get_listing(user: Annotated[User, Depends(get_current_user)]):
|
||||
repository = ListingRepository(engine)
|
||||
listings = await repository.get_listings(limit=5)
|
||||
logger.info(f"Fetched {len(listings)} listings")
|
||||
return {"listings": listings}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue