Merge pull request #2140 from cincodenada/ignore-does-not-exist

Ignore VariableDoesNotExist errors in debug logging
This commit is contained in:
Mouse Reeve 2022-11-14 12:26:06 -08:00 committed by GitHub
commit 36f511ebb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 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

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

@ -0,0 +1,20 @@
""" Logging utilities """
import logging
class IgnoreVariableDoesNotExist(logging.Filter):
"""
Filter to ignore VariableDoesNotExist errors
We intentionally pass nonexistent variables to templates a lot, so
these errors are not useful to us.
"""
def filter(self, record):
if record.exc_info:
(_, err_value, _) = record.exc_info
while err_value:
if type(err_value).__name__ == "VariableDoesNotExist":
return False
err_value = err_value.__context__
return True