In my Django Project, I get informed about IOErrors that happen sometimes when users upload data to the website. I wan't to turn off the email notification when IOErrors happen.
I found out how to write a filter, so I can get rid of the IOError. But how can I change this to log the error, but only to console, not per mail.
settings.py
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
},
'suppress_unreadable_post': {
'()': 'django.utils.log.CallbackFilter',
'callback': SuppressUnreadablePost,
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'include_html': True,
'class': 'django.utils.log.AdminEmailHandler'
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'myapp': {
'handlers': ['console'],
'level': 'DEBUG',
},
'ratelimitbackend': {
'handlers': ['console'],
'level': 'DEBUG',
},
}
}
And my filter:
import sys, traceback
class SuppressUnreadablePost(object):
def filter(self, record):
_, exception, tb = sys.exc_info()
if isinstance(exception, IOError):
for _, _, function, _ in traceback.extract_tb(tb):
if function == '_get_raw_post_data':
return False
return True
Ideas :)? Thank you!