core (log): add traceback when "exc_info" is set
This commit is contained in:
parent
9a0218ea10
commit
04f485057b
3 changed files with 35 additions and 26 deletions
|
|
@ -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 @@ class Logger(object):
|
|||
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 @@ class Logger(object):
|
|||
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 @@ class Logger(object):
|
|||
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 @@ def getLogger(name=C.LOG_BASE_LOGGER):
|
|||
|
||||
_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)
|
||||
|
|
|
|||
|
|
@ -34,11 +34,13 @@ class TwistedLogger(log.Logger):
|
|||
|
||||
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
|
||||
)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ def parseMainConf():
|
|||
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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue