fix exclude logging
This commit is contained in:
parent
03c3f4a4df
commit
2282748d1a
1 changed files with 56 additions and 54 deletions
|
|
@ -20,12 +20,21 @@ class CustomEncoder(json.JSONEncoder):
|
|||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
_EXCLUDE_FROM_LOGGING = ["base", "remove-bot", "remove-client", "restart-service"]
|
||||
_EXCLUDE_FROM_LOGGING = [
|
||||
"/",
|
||||
"/bot/remove/{did}",
|
||||
"/client/remove/{resource}",
|
||||
"/restart_{service}",
|
||||
]
|
||||
|
||||
|
||||
@web.middleware
|
||||
async def log_all_requests(request: Request, handler: Handler) -> StreamResponse:
|
||||
if request.match_info.route.name not in _EXCLUDE_FROM_LOGGING:
|
||||
if (
|
||||
not request.match_info.route.resource
|
||||
) or request.match_info.route.resource.canonical in _EXCLUDE_FROM_LOGGING:
|
||||
return await handler(request)
|
||||
|
||||
to_log = {
|
||||
"request": {
|
||||
"method": request.method,
|
||||
|
|
@ -33,14 +42,10 @@ async def log_all_requests(request: Request, handler: Handler) -> StreamResponse
|
|||
"path": request.path,
|
||||
"query_string": request.query_string,
|
||||
"headers": {h for h in request.headers.items()},
|
||||
"route_resource": request.match_info.route.resource.canonical,
|
||||
}
|
||||
}
|
||||
|
||||
if request.match_info.route.resource:
|
||||
to_log["request"][
|
||||
"route_resource"
|
||||
] = request.match_info.route.resource.canonical
|
||||
|
||||
try:
|
||||
if request.content_length:
|
||||
if request.content_type == "application/json":
|
||||
|
|
@ -81,6 +86,3 @@ async def log_all_requests(request: Request, handler: Handler) -> StreamResponse
|
|||
|
||||
finally:
|
||||
_LOGGER.debug(json.dumps(to_log, cls=CustomEncoder))
|
||||
|
||||
else:
|
||||
return await handler(request)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue