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?
Étienne Bersac pointed me in the right direction.
This is how I implemented it:
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
I suggest you implement a dedicated logging filter. Plug that filter on the internal werkzeug logger.
You can also investigate subclassing WSGI request handler log_request
method at https://github.com/pallets/werkzeug/blob/71cf9902012338f8ee98338fa7bba50572606637/src/werkzeug/serving.py#L378
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With