Filter out curl healthchecks from access logs
This commit is contained in:
parent
71e114b6fe
commit
bf31e929b5
1 changed files with 9 additions and 0 deletions
|
|
@ -35,6 +35,10 @@ class FilteredGunicornLogger(GunicornLogger):
|
||||||
".eot",
|
".eot",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_HEALTHCHECK_USER_AGENTS = (
|
||||||
|
"curl/",
|
||||||
|
)
|
||||||
|
|
||||||
def _should_skip_access_log(self, environ) -> bool:
|
def _should_skip_access_log(self, environ) -> bool:
|
||||||
path = environ.get("PATH_INFO") or ""
|
path = environ.get("PATH_INFO") or ""
|
||||||
if not path:
|
if not path:
|
||||||
|
|
@ -49,6 +53,11 @@ class FilteredGunicornLogger(GunicornLogger):
|
||||||
):
|
):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if lower_path == "/":
|
||||||
|
user_agent = (environ.get("HTTP_USER_AGENT") or "").lower()
|
||||||
|
if any(token in user_agent for token in self._HEALTHCHECK_USER_AGENTS):
|
||||||
|
return True
|
||||||
|
|
||||||
return any(lower_path.endswith(suffix) for suffix in self._STATIC_SUFFIXES)
|
return any(lower_path.endswith(suffix) for suffix in self._STATIC_SUFFIXES)
|
||||||
|
|
||||||
def access(self, resp, req, environ, request_time):
|
def access(self, resp, req, environ, request_time):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue