首页 > 解决方案 > 跳过一个端点的 Flask 日志记录?

问题描述

我有一个 Python Flask 应用程序。有一个运行状况检查经常命中一个端点 (/),我不想在日志中看到它。如何仅对一个 GET 端点禁用日志记录,而将其保留为其他所有端点?

标签: pythonflask

解决方案


É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

推荐阅读