Fix bug
This commit is contained in:
parent
57a6233779
commit
d0511f46c0
1 changed files with 17 additions and 14 deletions
|
@ -156,18 +156,21 @@ class SlowRequestMiddleware(object):
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
response = self.get_response(request)
|
response = self.get_response(request)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
response_time = time.time() - start_time
|
try:
|
||||||
url_name = resolve(request.path).url_name
|
response_time = time.time() - start_time
|
||||||
message = {
|
url_name = resolve(request.path).url_name
|
||||||
"url_name": url_name,
|
message = {
|
||||||
"response_time": response_time * 1000,
|
"url_name": url_name,
|
||||||
"profile": request.user.username,
|
"response_time": response_time * 1000,
|
||||||
"date": datetime.now().strftime("%Y/%m/%d"),
|
"profile": request.user.username,
|
||||||
"url": request.build_absolute_uri(),
|
"date": datetime.now().strftime("%Y/%m/%d"),
|
||||||
"method": request.method,
|
"url": request.build_absolute_uri(),
|
||||||
}
|
"method": request.method,
|
||||||
if response_time > 9:
|
}
|
||||||
logger_slow.info(json.dumps(message))
|
if response_time > 9:
|
||||||
if random.random() < 0.1:
|
logger_slow.info(json.dumps(message))
|
||||||
logger.info(json.dumps(message))
|
if random.random() < 0.1:
|
||||||
|
logger.info(json.dumps(message))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return response
|
return response
|
||||||
|
|
Loading…
Reference in a new issue