Django log error email configuration?

9 views
Skip to first unread message

prateek gupta

unread,
Jun 29, 2018, 3:15:54 AM6/29/18
to Django users
Hi All,

I am using Django 2.0.6, Python 3.6 and MySql 5.7.

For sending an email to the admin user in case of any error, I did following settings in my settings.py file-
DEBUG = False
# email configurations
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL = ""
SERVER_EMAIL = ""
EMAIL_HOST = ""
EMAIL_HOST_USER = ""
EMAIL_HOST_PASSWORD = ""
EMAIL_PORT = ""
DEFAULT_FROM_EMAIL = ""

# send server errors to admin
ADMINS = (('admin', 'ad...@example.com'),)
MANAGERS = ADMINS

# Logging configuration for production
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(asctime)s [%(levelname)s] %(filename)s:%(lineno)s %(funcName)s() : %(message)s'
        },
        'simple': {
            'format': '%(asctime)s [%(levelname)s] : %(message)s'
        },
    },
    'handlers': {
        'file': {
            'level': 'ERROR',
            'class': 'logging.FileHandler',
            'filename': 'error.log',
            'formatter': 'verbose'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler',
            'formatter': 'simple'
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'ERROR',
            'propagate': True,
        },
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    },
}

This configuration makes error.log file in my code base but I am not seeing any logs related to email here.
I have checked and email credentials,host,server etc all are correct.

Please share your suggestion how to make it works!



Reply all
Reply to author
Forward
0 new messages