How to see details of Django errors with Gunicorn?

后端 未结 5 1608
无人及你
无人及你 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:19

    1. sending errors to the console

    These are the loggers that use mail_admins by default (see django/utils/log.py):

        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
        'django.security': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
    

    you would need to change the handlers to go to the console so that it appears in your gunicorn log rather than send emails with mail_admins. Please note that it's not as chatty as when DEBUG=True.

     'loggers': {
        'django': {
            'level': 'ERROR',
            'handlers': ['console'],
        },
     }
    

    2. sending errors via mail_admins

    Also based on configuring logging, explicitly create a handler that calls mail_admins; e.g. based on django/utils/log.py:

     'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        },
     },
     'loggers': {
        'django': {
            'handlers': ['mail_admins'],
        },
     }
    

    This requires you to set email related settings.

    3. other solutions

    If you were not looking for solution #1, then your question is a duplicate of: How do you log server errors on django sites

提交回复
热议问题