How to see details of Django errors with Gunicorn?

后端 未结 5 1606
无人及你
无人及你 2021-01-31 08:33

I just deployed my Django (1.6) project with gunicorn and Nginx.

It seems to be working fine but I have one page were I\'m getting an HTTP 500 error and I can\'t find an

5条回答
  •  攒了一身酷
    2021-01-31 09:15

    From your comment I think this is a config problem in your django site, not a matter of gunicorn log, logs will not show more than django send to it.

    Here is an example of how you can configure django setting to send log to your file (instead of send it to admins by email as default):

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': True,
        'formatters': {
            'verbose': {
                'format': '%(asctime)s %(levelname)s [%(name)s:%(lineno)s] %(module)s %(process)d %(thread)d %(message)s'
            }
        },
        'handlers': {
            'gunicorn': {
                'level': 'DEBUG',
                'class': 'logging.handlers.RotatingFileHandler',
                'formatter': 'verbose',
                'filename': '/opt/djangoprojects/reports/bin/gunicorn.errors',
                'maxBytes': 1024 * 1024 * 100,  # 100 mb
            }
        },
        'loggers': {
            'gunicorn.errors': {
                'level': 'DEBUG',
                'handlers': ['gunicorn'],
                'propagate': True,
            },
        }
    }
    

    Read configuring logging (it provide a very well explanations of log settings options) and study the file django/utils/log.py to configure django loggin to appears more detailed on gunicorn logs.

    Also check this answer and this which provide setting examples to send logs errors directly to a file. And consider to use Sentry to handle log errors, as is recomended by django guys.

    Hope this helps.

提交回复
热议问题