Ignore VariableDoesNotExist errors in debug logging

They're so noisy as to make debug logging useless otherwise
This commit is contained in:
Joel Bradshaw 2022-05-05 13:29:07 -07:00
parent 7905be7de2
commit 7ae0db7f4a
2 changed files with 16 additions and 0 deletions

View file

@ -147,6 +147,9 @@ LOGGING = {
"require_debug_true": {
"()": "django.utils.log.RequireDebugTrue",
},
"ignore_missing_variable": {
"()": "bookwyrm.utils.log.IgnoreVariableDoesNotExist",
},
},
"handlers": {
# Overrides the default handler to make it log to console
@ -154,6 +157,7 @@ LOGGING = {
# console if DEBUG=False)
"console": {
"level": LOG_LEVEL,
"filters": ["ignore_missing_variable"],
"class": "logging.StreamHandler",
},
# This is copied as-is from the default logger, and is

12
bookwyrm/utils/log.py Normal file
View file

@ -0,0 +1,12 @@
import logging
class IgnoreVariableDoesNotExist(logging.Filter):
def filter(self, record):
if(record.exc_info):
(errType, errValue, _) = record.exc_info
while errValue:
if type(errValue).__name__ == 'VariableDoesNotExist':
return False
errValue = errValue.__context__
return True