Skip to content

Commit 901b8b5

Browse files
committed
chore: Log start of requests at same level as end
It is useful when reading through logs to see when each request was received to make sense of subsequent events.
1 parent de15ec5 commit 901b8b5

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/blueapi/service/main.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -583,20 +583,18 @@ async def log_request_details(
583583
) -> Response:
584584
"""Middleware to log all request's host, method, path, status and request and
585585
body"""
586+
log = LOGGER.debug if request.url.path == "/healthz" else LOGGER.info
586587
request_body = await request.body()
587588
client = request.client or Address("Unknown", -1)
588589
log_message = f"{client.host}:{client.port} {request.method} {request.url.path}"
589590
extra = {
590591
"request_body": request_body,
591592
}
592-
LOGGER.debug(log_message, extra=extra)
593+
log(log_message, extra=extra)
593594

594595
response = await call_next(request)
595596
log_message += f" {response.status_code}"
596-
if request.url.path == "/healthz":
597-
LOGGER.debug(log_message, extra=extra)
598-
else:
599-
LOGGER.info(log_message, extra=extra)
597+
log(log_message, extra=extra)
600598

601599
return response
602600

0 commit comments

Comments
 (0)