feat: base 日志默认记录耗时大于2s的
This commit is contained in:
parent
b4cfdd693a
commit
42a4332b87
|
@ -325,6 +325,7 @@ class MyLoggingMixin(object):
|
||||||
response = super().finalize_response(
|
response = super().finalize_response(
|
||||||
request, response, *args, **kwargs
|
request, response, *args, **kwargs
|
||||||
)
|
)
|
||||||
|
self.log["response_ms"] = self._get_response_ms()
|
||||||
# Ensure backward compatibility for those using _should_log hook
|
# Ensure backward compatibility for those using _should_log hook
|
||||||
should_log = (
|
should_log = (
|
||||||
self._should_log if hasattr(self, "_should_log") else self.should_log
|
self._should_log if hasattr(self, "_should_log") else self.should_log
|
||||||
|
@ -353,7 +354,7 @@ class MyLoggingMixin(object):
|
||||||
"method": request.method,
|
"method": request.method,
|
||||||
"query_params": self._clean_data(request.query_params.dict()),
|
"query_params": self._clean_data(request.query_params.dict()),
|
||||||
"user": self._get_user(request),
|
"user": self._get_user(request),
|
||||||
"response_ms": self._get_response_ms(),
|
# "response_ms": self._get_response_ms(),
|
||||||
"response": self._clean_data(rendered_content),
|
"response": self._clean_data(rendered_content),
|
||||||
"status_code": response.status_code,
|
"status_code": response.status_code,
|
||||||
"agent": self._get_agent(request),
|
"agent": self._get_agent(request),
|
||||||
|
@ -447,7 +448,8 @@ class MyLoggingMixin(object):
|
||||||
By default, check if the request method is in logging_methods.
|
By default, check if the request method is in logging_methods.
|
||||||
"""
|
"""
|
||||||
return self.logging_methods == "__all__" or response.status_code > 404 or response.status_code == 400 \
|
return self.logging_methods == "__all__" or response.status_code > 404 or response.status_code == 400 \
|
||||||
or (request.method in self.logging_methods and response.status_code not in [401, 403, 404])
|
or (request.method in self.logging_methods and response.status_code not in [401, 403, 404])\
|
||||||
|
or (self.log.get("response_ms", 0) > 2000)
|
||||||
|
|
||||||
def _clean_data(self, data):
|
def _clean_data(self, data):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue