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.
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
:And then use it when you start gunicorn:
gunicorn server:app -c config/gunicorn.py
The
pre_request
hook wasn't working for me. I used the answer from https://stackoverflow.com/a/52455408/2339067 to create the followinggunicorn.conf.py
file: