-
-
Notifications
You must be signed in to change notification settings - Fork 273
Suppressing the KeyError for an unbind() call #171
Copy link
Copy link
Closed
Description
Hi,
This is a suggestion for possible improvement in the logic of invoking the unbind() method on the BoundLogger. We recently deployed structlog in our Django project. Everything seemed to work fine until we started getting a bunch of KeyErrors while unbinding parameters.
We realised that we had a recursive logic where on a child stack the context variable would get unbound and when the control came back to the parent stack, another call to unbind crashed the flow.
For now, we added a new wrapper class over the BoundLogger which simply suppresses the exception:
from structlog.stdlib import BoundLogger
class BoundLoggerWrapper(BoundLogger):
def unbind(self, *keys):
try:
return super(BoundLoggerWrapper, self).unbind(*keys)
except KeyError:
return self.bind()Just wanted to check whether doing this might have any unwanted consequences.
Thanks for this wonderful library!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels