# HG changeset patch # User Goffi # Date 1551611095 -3600 # Node ID ad00f61fd9f500e0b384b8b6f27f1ca69635f1e3 # Parent 6aa22011bc6d0be0f36b6ab56c7ebee240eb6427 core (log): add traceback when "exc_info" is set diff -r 6aa22011bc6d -r ad00f61fd9f5 sat/core/log.py --- a/sat/core/log.py Sun Mar 03 08:57:36 2019 +0100 +++ b/sat/core/log.py Sun Mar 03 12:04:55 2019 +0100 @@ -24,6 +24,7 @@ from sat.core.constants import Const as C from sat.tools.common.ansi import ANSI as A from sat.core import exceptions +import traceback backend = None _loggers = {} @@ -55,14 +56,20 @@ self.post_treat = other.post_treat self._name = other._name - def out(self, message, level=None): + def addTraceback(self, message): + tb = traceback.format_exc() + return message + "\n==== traceback ====\n" + tb + + def out(self, message, level=None, **kwargs): """Actually log the message @param message: formatted message """ + if kwargs.get('exc_info', False): + message = self.addTraceback(message) print message - def log(self, level, message): + def log(self, level, message, **kwargs): """Print message @param level: one of C.LOG_LEVELS @@ -71,9 +78,9 @@ try: formatted = self.format(level, message) if self.post_treat is None: - self.out(formatted, level) + self.out(formatted, level, **kwargs) else: - self.out(self.post_treat(level, formatted), level) + self.out(self.post_treat(level, formatted), level, **kwargs) except Filtered: pass @@ -110,20 +117,20 @@ else: raise e - def debug(self, msg): - self.log(C.LOG_LVL_DEBUG, msg) + def debug(self, msg, **kwargs): + self.log(C.LOG_LVL_DEBUG, msg, **kwargs) - def info(self, msg): - self.log(C.LOG_LVL_INFO, msg) + def info(self, msg, **kwargs): + self.log(C.LOG_LVL_INFO, msg, **kwargs) - def warning(self, msg): - self.log(C.LOG_LVL_WARNING, msg) + def warning(self, msg, **kwargs): + self.log(C.LOG_LVL_WARNING, msg, **kwargs) - def error(self, msg): - self.log(C.LOG_LVL_ERROR, msg) + def error(self, msg, **kwargs): + self.log(C.LOG_LVL_ERROR, msg, **kwargs) - def critical(self, msg): - self.log(C.LOG_LVL_CRITICAL, msg) + def critical(self, msg, **kwargs): + self.log(C.LOG_LVL_CRITICAL, msg, **kwargs) class FilterName(object): @@ -379,17 +386,17 @@ _root_logger = getLogger() -def debug(msg): - _root_logger.debug(msg) +def debug(msg, **kwargs): + _root_logger.debug(msg, **kwargs) -def info(msg): - _root_logger.info(msg) +def info(msg, **kwargs): + _root_logger.info(msg, **kwargs) -def warning(msg): - _root_logger.warning(msg) +def warning(msg, **kwargs): + _root_logger.warning(msg, **kwargs) -def error(msg): - _root_logger.error(msg) +def error(msg, **kwargs): + _root_logger.error(msg, **kwargs) -def critical(msg): - _root_logger.critical(msg) +def critical(msg, **kwargs): + _root_logger.critical(msg, **kwargs) diff -r 6aa22011bc6d -r ad00f61fd9f5 sat/core/log_config.py --- a/sat/core/log_config.py Sun Mar 03 08:57:36 2019 +0100 +++ b/sat/core/log_config.py Sun Mar 03 12:04:55 2019 +0100 @@ -34,11 +34,13 @@ self.twisted_log = twisted_log - def out(self, message, level=None): + def out(self, message, level=None, **kwargs): """Actually log the message @param message: formatted message """ + if kwargs.get('exc_info', False): + message = self.addTraceback(message) self.twisted_log.msg( message.encode("utf-8", "ignore"), sat_logged=True, level=level ) diff -r 6aa22011bc6d -r ad00f61fd9f5 sat/tools/config.py --- a/sat/tools/config.py Sun Mar 03 08:57:36 2019 +0100 +++ b/sat/tools/config.py Sun Mar 03 12:04:55 2019 +0100 @@ -75,7 +75,7 @@ try: config.read(C.CONFIG_FILES) except Exception as e: - log.error(_(u"Can't read main config: {msg}").format(msg=e)) + log.error(_(u"Can't read main config: {msg}").format(msg=e), exc_info=True) return config