Skip to content

Commit

Permalink
fix: use new uvicorn logger in log_request_middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Impro02 committed Apr 24, 2024
1 parent 961d9e8 commit 59149b6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions alphaz_next/core/_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import http
import time
from typing import Optional, Sequence
from loguru import logger

# FASTAPI
from fastapi import Request, Response
Expand All @@ -12,7 +13,8 @@

# CORE
from alphaz_next.core.constants import HeaderEnum
from alphaz_next.core.uvicorn_logger import UVICORN_LOGGER

uvicorn_logger = logger.bind(service="uvicorn")


class CORSMiddleware(_CORSMiddleware):
Expand Down Expand Up @@ -72,7 +74,8 @@ async def log_request_middleware(request: Request, call_next):

response.headers[HeaderEnum.PROCESS_TIME.value] = str(process_time)

UVICORN_LOGGER.info(
f'{host}:{port} - "{request.method} {url}" {response.status_code} {status_phrase} {formatted_process_time}ms'
)
with uvicorn_logger.contextualize(endpoint=request.base_url):
uvicorn_logger.info(
f'{host}:{port} - "{request.method} {url}" {response.status_code} {status_phrase} {formatted_process_time}ms'
)
return response

0 comments on commit 59149b6

Please sign in to comment.