How to exclude 404 error messages from logging to email?

Viewed 21

Good afternoon. I have this type of logs in the settings:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },

    'formatters': {
        'verbose': {
            'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
            'style': '{',
        },
        'simple': {
            'format': '{levelname} {message}',
            'style': '{',
        },
    },

    'handlers': {
        'console': {
            'level': 'INFO',
            'class': 'logging.StreamHandler',
        },

        'mail_admins': {
            'level': 'WARNING',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler',
            'include_html': True,
        },
    },

    'loggers': {
        '': {
            'handlers': ['console', 'mail_admins'],
            'level': 'DEBUG',
            'propagate': False,
        },
    }
}

I receive all messages of the level of warning and above in the email. Due to various robots, spammers or other users looking for hidden files and folders, I get a lot of 404 (page not found) error messages.

How can I stop receiving information about 404 errors?

1 Answers

This is thanks to the mail_admins handler, that sends you any WARNING level and above error by email, see doc

As suggested in docs, you can subclass this handler and use your new custom handler instead.

Related