Handle errors in the log-emitting same way as in native handlers
@@ -48,6 +48,8 @@ class K8sPoster(logging.Handler):
return has_ref and not skipped and super().filter(record)
def emit(self, record):
+ # Same try-except as in e.g. `logging.StreamHandler`.
+ try:
type = (
"Debug" if record.levelno <= logging.DEBUG else
"Normal" if record.levelno <= logging.INFO else
@@ -62,6 +64,8 @@ class K8sPoster(logging.Handler):
type=type,
reason=reason,
message=message))
+ except Exception:
+ self.handleError(record)
class ObjectLogger(logging.LoggerAdapter):
