How to use Django logging with gunicorn

两盒软妹~` 提交于 2019-12-03 17:37:02

问题


I have a Django 1.6 site running with gunicorn, managed by supervisor. During tests and runserver I have logging on the console, but with gunicorn the statements don't show up anywhere (not even ERROR level logs). They should be in /var/log/supervisor/foo-stderr---supervisor-51QcIl.log but they're not. I have celery running on a different machine using supervisor and its debug statements show up fine in its supervisor error file.

Edit: Running gunicorn in the foreground shows that none of my error messages are being logged to stderr like they are when running manage.py. This is definitely a gunicorn problem and not a supervisor problem.


回答1:


I got a response on GitHub:

https://github.com/benoitc/gunicorn/issues/708

Since you have passed disable_existing_loggers the Gunicorn loggers are disabled when Django loads your logging configuration. If you are setting this because you want to disable some default Django logging configuration, make sure you add back the gunicorn loggers, gunicorn.error and gunicorn.access with whatever handlers you want.




回答2:


In /etc/supervisor/conf.d/your-app.confyou should set log paths:

stdout_logfile=/var/log/your-app.log
stderr_logfile=/var/log/your-app.log



回答3:


First, in your supervisor config for the gunicorn script, be sure to define

stdout_logfile=/path/to/logfile.log
redirect_stderr=true

That will make stdout and stderr go to the same file.
Now, on your gunicorn script, be sure to call the process with the following argument

gunicorn YourWSGIModule:app --log-level=critical


来源:https://stackoverflow.com/questions/21340049/how-to-use-django-logging-with-gunicorn

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