Skip to content

Commit

Permalink
Filter 404 Not Found logs from AdminEmailHandler
Browse files Browse the repository at this point in the history
There is no point in sending hundreds of 404 logs every day.
  • Loading branch information
eht16 committed Apr 4, 2020
1 parent 23e8033 commit fa80c40
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion geany/settings.py
Expand Up @@ -464,6 +464,14 @@
#########################
# LOGGING #
#########################
def skip_404_not_found(record):
# filter 404 Not Found log messages and ignore them to prevent sending lots of mails
# via AdminEmailHandler
if record.name == 'django.request' and getattr(record, 'status_code', 0) == 404:
return False
return True


logging.captureWarnings(True) # log warnings using the logging subsystem
LOGGING = {
'version': 1,
Expand All @@ -485,6 +493,10 @@
'request_id': {
'()': 'log_request_id.filters.RequestIDFilter'
},
'skip_404_not_found': {
'()': 'django.utils.log.CallbackFilter',
'callback': skip_404_not_found,
}
},
'handlers': {
'console': {
Expand All @@ -496,7 +508,7 @@
'mail_admins': {
'level': 'WARN',
'class': 'django.utils.log.AdminEmailHandler',
'filters': ['require_debug_false', 'request_id']
'filters': ['require_debug_false', 'request_id', 'skip_404_not_found']
},
'file': {
'level': 'DEBUG',
Expand Down

0 comments on commit fa80c40

Please sign in to comment.