Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/blueapi/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,16 +594,19 @@ def start(config: ApplicationConfig):
async def log_request_details(
request: Request, call_next: Callable[[Request], Awaitable[StreamingResponse]]
) -> Response:
"""Middleware to log all request's host, method, path, status and request and
body"""
log = LOGGER.debug if request.url.path == "/healthz" else LOGGER.info
"""Middleware to log request's host, method, path, status and request and
body

Logs GET as debug, all else as info."""
log = LOGGER.debug if request.method == "GET" else LOGGER.info
request_body = await request.body()
client = request.client or Address("Unknown", -1)
log_message = f"{client.host}:{client.port} {request.method} {request.url.path}"
extra = {
"request_body": request_body,
}
log(log_message, extra=extra)
if request.method != "GET":
log(log_message, extra=extra)

response = await call_next(request)
log_message += f" {response.status_code}"
Expand Down
Loading