fix logger

This commit is contained in:
Robert Resch 2022-10-01 14:04:49 +02:00
parent d759fc6d0e
commit b2f2ebb59b

View file

@ -38,8 +38,8 @@ class _AiohttpFilter(logging.Filter):
_LOGGER = get_logger("webserver") _LOGGER = get_logger("webserver")
# Add logging filter above to aiohttp.access # Add logging filter above to aiohttp.access
logging.getLogger("aiohttp.access").addFilter(_AiohttpFilter()) logging.getLogger("aiohttp.access").addFilter(_AiohttpFilter())
_LOGGER_PROXY = logging.getLogger("web_proxy") _LOGGER_PROXY = get_logger("web_proxy")
_LOGGER_WEB_LOG = logging.getLogger("web_log") _LOGGER_WEB_LOG = get_logger("web_log")
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
@ -381,10 +381,12 @@ class WebServer:
async def _handle_log(self, request: Request) -> Response: async def _handle_log(self, request: Request) -> Response:
to_log = {} to_log = {}
try: try:
to_log = { to_log.update(
"query_string": request.query_string, {
"headers": set(request.headers.items()), "query_string": request.query_string,
} "headers": set(request.headers.items()),
}
)
if request.content_length: if request.content_length:
to_log["body"] = set(await request.post()) to_log["body"] = set(await request.post())
except Exception: # pylint: disable=broad-except except Exception: # pylint: disable=broad-except
@ -392,6 +394,6 @@ class WebServer:
"An exception occurred during logging the request.", exc_info=True "An exception occurred during logging the request.", exc_info=True
) )
finally: finally:
_LOGGER_WEB_LOG.debug(json.dumps(to_log, cls=CustomEncoder)) _LOGGER_WEB_LOG.info(json.dumps(to_log, cls=CustomEncoder))
return web.Response() return web.Response()