python - 跳过一个端点的 Flask 日志记录?
问题描述
我有一个 Python Flask 应用程序。有一个运行状况检查经常命中一个端点 (/),我不想在日志中看到它。如何仅对一个 GET 端点禁用日志记录,而将其保留为其他所有端点?
解决方案
Étienne Bersac 为我指明了正确的方向。
这就是我实现它的方式:
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
推荐阅读
- android - android - 在 AcknowledgePurchaseResponseListener 中获取对视图的引用
- mysql - SQL:如何选择 id 在逗号分隔的字符串中的行?
- python - 如何验证井字游戏结束场景
- flutter - 如何获取文本字段的值并在文本中但在另一个屏幕中返回?
- angular - 如何在 Angular 中初始化 Firebase 应用检查
- c# - SQL 参数和 int 值
- php - PHP,向数组添加键以形成正确的 SOAP 请求
- c - C中的无效整数
- javascript - 如何处理 d3.js 中的多对多关系
- python - 使用 python 来改变图像的对比度,但它太慢了