logging: Move exc_info to common log.

The keyword parameters are populated to common log and exc_info should be
common to all methods anyway.

This change the default to be exc_info=False for all cases similar to the
standard python.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
pull/1004/head
Alon Bar-Lev 2025-04-30 17:58:29 +03:00
rodzic 6451d26c91
commit 686f1ca90f
1 zmienionych plików z 12 dodań i 11 usunięć

Wyświetl plik

@ -125,7 +125,7 @@ class Logger:
def getEffectiveLevel(self):
return self.level or getLogger().level or _DEFAULT_LEVEL
def log(self, level, msg, *args, extra=None):
def log(self, level, msg, *args, exc_info=False, extra=None):
if self.isEnabledFor(level):
if args:
if isinstance(args[0], dict):
@ -138,6 +138,16 @@ class Logger:
for h in handlers:
h.emit(record)
tb = None
if isinstance(exc_info, BaseException):
tb = exc_info
elif hasattr(sys, "exc_info"):
tb = sys.exc_info()[1]
if tb:
buf = io.StringIO()
sys.print_exception(tb, buf)
self.log(ERROR, buf.getvalue())
def debug(self, msg, *args, **kwargs):
self.log(DEBUG, msg, *args, **kwargs)
@ -153,17 +163,8 @@ class Logger:
def critical(self, msg, *args, **kwargs):
self.log(CRITICAL, msg, *args, **kwargs)
def exception(self, msg, *args, exc_info=True, **kwargs):
def exception(self, msg, *args, **kwargs):
self.log(ERROR, msg, *args, **kwargs)
tb = None
if isinstance(exc_info, BaseException):
tb = exc_info
elif hasattr(sys, "exc_info"):
tb = sys.exc_info()[1]
if tb:
buf = io.StringIO()
sys.print_exception(tb, buf)
self.log(ERROR, buf.getvalue())
def addHandler(self, handler):
self.handlers.append(handler)