Mercurial > libervia-backend
changeset 2836:ad00f61fd9f5
core (log): add traceback when "exc_info" is set
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 03 Mar 2019 12:04:55 +0100 |
parents | 6aa22011bc6d |
children | e2005dd39c92 |
files | sat/core/log.py sat/core/log_config.py sat/tools/config.py |
diffstat | 3 files changed, 35 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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 )
--- 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