11

I have struggling with django(1.5.1) error email reports not being sent.

here is my conf settings to use with gmail

DEFAULT_FROM_EMAIL = 'server@example.com'

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'server@example.com'
EMAIL_HOST_PASSWORD = 'passs'
EMAIL_USE_TLS = True

SERVER_EMAIL = 'server@example.com'

ADMINS = (
    ('Adam Min', 'adam@example.com'),
)

If I add MANAGERS = ADMINS then I receive emails for 404's but without MANAGERS setting I receive nothing at all.

I have created a buggy url so I can test this.

Also I found this similar Q Django emailing on errors but it didn't help me.

EDIT: also in config I have DEBUG = False and this

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s [%(asctime)s] %(module)s %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(message)s'
        },
    },
    'filters': {
        'require_debug_false': {
                 '()': 'django.utils.log.RequireDebugFalse',
        }
    },
    'handlers': {
        'console': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'formatter': 'simple'
        },
        'file': {
            'class': 'logging.handlers.RotatingFileHandler',
            'formatter': 'verbose',
            'filename': '/var/www/logs/ibiddjango.log',
            'maxBytes': 1024000,
            'backupCount': 3,
        },
        'sql': {
            'class': 'logging.handlers.RotatingFileHandler',
            'formatter': 'verbose',
            'filename': '/var/www/logs/sql.log',
            'maxBytes': 102400,
            'backupCount': 3,
        },
        'commands': {
            'class': 'logging.handlers.RotatingFileHandler',
            'formatter': 'verbose',
            'filename': '/var/www/logs/commands.log',
            'maxBytes': 10240,
            'backupCount': 3,
        },
        'mail_admins': {
             'level': 'ERROR',
             'filters': ['require_debug_false'],
             'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django': {
            'handlers': ['file', 'console'],
            'propagate': True,
            'level': 'DEBUG',
        },
        'django.db.backends': {
            'handlers': ['sql', 'console'],
            'propagate': False,
            'level': 'WARNING',
        },
        'scheduling': {
            'handlers': ['commands', 'console'],
            'propagate': True,
            'level': 'DEBUG',
        },
    }
}

What am I missing?

Community
  • 1
  • 1
dnuske
  • 558
  • 7
  • 21

1 Answers1

19

it seems that your problem is in your logging configuration: in settings.py LOGGING:

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

This config indicate that mail_admins handler work only in DEBUG = False because the filter used. If you try with mode debug false or you can activate this handler in debug mode just comment the filters:

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

Edit:

Your configuration doesn't call mail_admins handler. Add it to the django logger like this:

'loggers': {
    'django': {
        'handlers': ['file', 'console', 'mail_admins',],
        'propagate': True,
        'level': 'DEBUG',
    },
Mounir
  • 11,306
  • 2
  • 27
  • 34
  • Hi, thank you for answer. I tried out commenting that line but the behavior continues. I don't see any anomalies, the log file works perfectly and so the rest, except the email in error 500. (I still receive it in 404 if I add MANAGERS) – dnuske Jun 29 '13 at 02:26
  • It worked, you can't imagine how thankful I am, good karma to you =) – dnuske Jun 29 '13 at 21:42