From 9acea8adf4fdfa39b0feafbf63a86c38e72022f1 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Tue, 12 Jan 2021 20:51:49 +0100 Subject: [PATCH] Fixed logging of exception in debug_or_exception handler for python version <3.8 --- cps/logger.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cps/logger.py b/cps/logger.py index d2a41b71..b204de31 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -44,10 +44,22 @@ logging.addLevelName(logging.CRITICAL, "CRIT") class _Logger(logging.Logger): def debug_or_exception(self, message, *args, **kwargs): - if is_debug_enabled(): - self.exception(message, stacklevel=2, *args, **kwargs) + if sys.version_info > (3, 7): + if is_debug_enabled(): + self.exception(message, stacklevel=2, *args, **kwargs) + else: + self.error(message, stacklevel=2, *args, **kwargs) + elif sys.version_info > (3, 0): + if is_debug_enabled(): + self.exception(message, stack_info=True, *args, **kwargs) + else: + self.error(message, *args, **kwargs) else: - self.error(message, stacklevel=2, *args, **kwargs) + if is_debug_enabled(): + self.exception(message, *args, **kwargs) + else: + self.error(message, *args, **kwargs) + def debug_no_auth(self, message, *args, **kwargs): if message.startswith("send: AUTH"):