From 7ae0db7f4ae3edffdd5d54e25d3fb5fe9339e590 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Thu, 5 May 2022 13:29:07 -0700 Subject: [PATCH 1/3] Ignore VariableDoesNotExist errors in debug logging They're so noisy as to make debug logging useless otherwise --- bookwyrm/settings.py | 4 ++++ bookwyrm/utils/log.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 bookwyrm/utils/log.py diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index e16c576e1..236413fe8 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -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 diff --git a/bookwyrm/utils/log.py b/bookwyrm/utils/log.py new file mode 100644 index 000000000..8ad86895c --- /dev/null +++ b/bookwyrm/utils/log.py @@ -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 From 7014786fe03a73c7c8fe525aaad19384aa05c159 Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Sun, 5 Jun 2022 13:41:00 -0700 Subject: [PATCH 2/3] Run formatters --- bookwyrm/utils/log.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/utils/log.py b/bookwyrm/utils/log.py index 8ad86895c..4ea24d81d 100644 --- a/bookwyrm/utils/log.py +++ b/bookwyrm/utils/log.py @@ -3,10 +3,10 @@ import logging class IgnoreVariableDoesNotExist(logging.Filter): def filter(self, record): - if(record.exc_info): + if record.exc_info: (errType, errValue, _) = record.exc_info while errValue: - if type(errValue).__name__ == 'VariableDoesNotExist': + if type(errValue).__name__ == "VariableDoesNotExist": return False errValue = errValue.__context__ return True From c9adb7ff129bdb75fcbe97c896347cfb889683a0 Mon Sep 17 00:00:00 2001 From: Ell Bradshaw Date: Mon, 14 Nov 2022 00:48:59 -0800 Subject: [PATCH 3/3] Linting fixes --- bookwyrm/utils/log.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bookwyrm/utils/log.py b/bookwyrm/utils/log.py index 4ea24d81d..70f32ef03 100644 --- a/bookwyrm/utils/log.py +++ b/bookwyrm/utils/log.py @@ -1,12 +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: - (errType, errValue, _) = record.exc_info - while errValue: - if type(errValue).__name__ == "VariableDoesNotExist": + (_, err_value, _) = record.exc_info + while err_value: + if type(err_value).__name__ == "VariableDoesNotExist": return False - errValue = errValue.__context__ - return True + err_value = err_value.__context__ + return True