跳过Flask记录一个端点? [英] Skip Flask logging for one endpoint?
本文介绍了跳过Flask记录一个端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Python Flask应用程序.有一个运行状况检查会频繁地影响到一个端点(/),我希望在日志中看不到它.如何仅禁用一个GET端点的日志记录,而保留其他所有日志记录?
I have a Python Flask application. There is a healthcheck that hits one endpoint (/) a lot, and I'd like to not see it in logs. How do I disable logging for only one GET endpoint, and leave it be for everything else?
推荐答案
ÉtienneBersac指出了我正确的方向.
Étienne Bersac pointed me in the right direction.
这是我的实现方式:
from werkzeug import serving
parent_log_request = serving.WSGIRequestHandler.log_request
def log_request(self, *args, **kwargs):
if self.path == '/healthcheck':
return
parent_log_request(self, *args, **kwargs)
def filter_healthcheck_logs():
serving.WSGIRequestHandler.log_request = log_request
这篇关于跳过Flask记录一个端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文