improve logging
This commit is contained in:
parent
36d7c468fa
commit
496c75b05f
2 changed files with 38 additions and 33 deletions
|
|
@ -46,14 +46,22 @@ async def log_all_requests(request: Request, handler: Handler) -> StreamResponse
|
|||
}
|
||||
}
|
||||
|
||||
try:
|
||||
try:
|
||||
if request.content_length:
|
||||
if request.content_type == "application/json":
|
||||
to_log["request"]["body"] = await request.json()
|
||||
else:
|
||||
to_log["request"]["body"] = {h for h in await request.post()}
|
||||
except Exception:
|
||||
_LOGGER.exception(
|
||||
"An exception occurred during logging the request.", exc_info=True
|
||||
)
|
||||
raise
|
||||
|
||||
response = await handler(request)
|
||||
|
||||
try:
|
||||
if response is None:
|
||||
_LOGGER.warning( # type:ignore[unreachable]
|
||||
"Response was null!"
|
||||
|
|
@ -74,16 +82,15 @@ async def log_all_requests(request: Request, handler: Handler) -> StreamResponse
|
|||
to_log["response"]["body"] = response.text
|
||||
|
||||
return response
|
||||
except Exception:
|
||||
_LOGGER.exception(
|
||||
"An exception occurred during logging the response", exc_info=True
|
||||
)
|
||||
raise
|
||||
|
||||
except web.HTTPNotFound:
|
||||
_LOGGER.debug(f"Request path {request.raw_path} not found")
|
||||
raise
|
||||
|
||||
except Exception:
|
||||
_LOGGER.exception(
|
||||
"An exception occurred in the logging middleware.", exc_info=True
|
||||
)
|
||||
raise
|
||||
|
||||
finally:
|
||||
_LOGGER.debug(json.dumps(to_log, cls=CustomEncoder))
|
||||
|
|
|
|||
|
|
@ -333,10 +333,8 @@ class WebServer:
|
|||
)
|
||||
else:
|
||||
# handle json
|
||||
jdata = read_body.decode("utf8")
|
||||
jdata = json.loads(jdata)
|
||||
async with session.request(
|
||||
request.method, request.url, json=jdata
|
||||
request.method, request.url, json=request.json()
|
||||
) as resp:
|
||||
response = await resp.text()
|
||||
proxymodelog.info(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue