Disable logging in gunicorn for a specific request / URL / endpoint

最后都变了- 提交于 2019-12-10 15:38:56

问题


Recently, there was the question of how to disable logging in Python Flask for a specific endpoint (Skip Flask logging for one endpoint?).

This makes sense for example for /healthcheck which you don't want to clutter your logs.

I solved this for Flask, but when running Flask using Gunicorn my solution doesn't work anymore.

How do I achieve this using Gunicorn? I want regular logging behavior, but not have any logs for the /healthcheck endpoint.


回答1:


I figured it out - you need to override the pre_request hook.

This can be done as follows:

You need to create a config file, e.g. config/gunicorn.py:

def pre_request(worker, req):
    if req.path == '/healthcheck':
        return
    worker.log.debug("%s %s" % (req.method, req.path))

And then use it when you start gunicorn: gunicorn server:app -c config/gunicorn.py



来源:https://stackoverflow.com/questions/57416645/disable-logging-in-gunicorn-for-a-specific-request-url-endpoint

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!