From 8209af5726ccd1cbc361ae627578fa6e1a017d37 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Mon, 3 May 2021 16:53:34 +0200 Subject: [PATCH] print exc_info only on debug --- mylogger.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mylogger.py b/mylogger.py index 3fba1ff..5a957d8 100644 --- a/mylogger.py +++ b/mylogger.py @@ -6,12 +6,17 @@ logging.addLevelName(DEBUG_LEVELV_NUM, "DEBUGV") class CustomLogger(logging.Logger): - # pylint: disable=too-many-arguments + # pylint: disable=too-many-arguments,unused-argument,arguments-differ + def _log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, exc_info_debug=False, **kwargs): + if exc_info_debug and self.isEnabledFor(logging.DEBUG): + exc_info = True + super()._log(level, msg, args, exc_info, extra, stack_info) + def __new_style_log(self, level, msg, args, exc_info=None, extra=None, stack_info=False, **kwargs): if kwargs.pop('style', "%") == "{": # optional msg = msg.format(*args) args = [] - super()._log(level, msg, args, exc_info, extra, stack_info) + self._log(level, msg, args, exc_info, extra, stack_info) def debugv(self, msg, *args, **kwargs): if self.isEnabledFor(DEBUG_LEVELV_NUM):