I am using Gunicorn in front of a Python Flask app. I am able to configure the access log format using the --access-log-format
command line parameter when I run gunicorn
. But I can't figure out how to configure the error logs.
I would be fine with the default format, except it's not consistent. It looks like Gunicorn status messages have one format, but application exceptions have a different format. This is making it difficult to use log aggregation.
For example, here a few messages from Gunicorn's error log. The first few lines have a different format than the exception line. Event the datetime format is different.
[2017-07-13 16:33:24 +0000] [15] [INFO] Booting worker with pid: 15
[2017-07-13 16:33:24 +0000] [16] [INFO] Booting worker with pid: 16
[2017-07-13 16:33:24 +0000] [17] [INFO] Booting worker with pid: 17
[2017-07-13 16:33:24 +0000] [18] [INFO] Booting worker with pid: 18
[2017-07-13 18:31:11,580] ERROR in app: Exception on /api/users [POST]
Traceback (most recent call last):File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1982, in wsgi_appresponse = self.full_dispatch_request()File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1614, in full_dispatch_requestrv = self.handle_user_exception(e)
...
What's the best way to configure Gunicorn to use consistent formatting for its error logs?