Robustness fix for logcontext filter

Make the logcontext filter not explode if it somehow ends up with a logcontext
of None, since that infinite-loops the whole logging system.
This commit is contained in:
Richard van der Hoff 2018-08-20 18:20:07 +01:00
parent 80bf7d3580
commit 55e6bdf287
1 changed files with 7 additions and 1 deletions

View File

@ -385,7 +385,13 @@ class LoggingContextFilter(logging.Filter):
context = LoggingContext.current_context()
for key, value in self.defaults.items():
setattr(record, key, value)
context.copy_to(record)
# context should never be None, but if it somehow ends up being, then
# we end up in a death spiral of infinite loops, so let's check, for
# robustness' sake.
if context is not None:
context.copy_to(record)
return True