From bfac62c2b753d5c27997810138d328a0f9261bd6 Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Wed, 6 Oct 2021 21:11:43 +0200 Subject: [PATCH] improve logging on serialization error --- pyquarantine/__init__.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pyquarantine/__init__.py b/pyquarantine/__init__.py index bfb7886..aea3d3c 100644 --- a/pyquarantine/__init__.py +++ b/pyquarantine/__init__.py @@ -96,15 +96,14 @@ class QuarantineMilter(Milter.Base): def msg_as_bytes(self): try: data = self.msg.as_bytes() - except Exception: - self.logger.warning( - "unable to serialize message as bytes, " - "try to serialize as str and encode") + except Exception as e: + self.logger.warning(f"unable to serialize message as bytes: {e}") try: + self.logger.warning("try to serialize as str and encode") data = self.msg.as_string().encode("ascii", errors="replace") except Exception as e: - self.logger.exception( - "unable to serialize message, giving up") + self.logger.error( + f"unable to serialize message, giving up: {e}") raise e return data