提交 12a9d7f9 编写于 作者: L Lukáš Doktor

utils.stacktrace: Allow passing logger as well as log name

Sometimes we already have the logger so it makes a little sense to pass
logger name only to obtain the logger again in this function. Lets allow
both.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 2403f129
......@@ -32,17 +32,18 @@ def log_exc_info(exc_info, logger=''):
Log exception info to logger_name.
:param exc_info: Exception info produced by sys.exc_info()
:param logger: Name of the logger (defaults to '')
:param logger: Name or logger instance (defaults to '')
"""
log = logging.getLogger(logger)
log.error('')
if isinstance(logger, basestring):
logger = logging.getLogger(logger)
logger.error('')
called_from = inspect.currentframe().f_back
log.error("Reproduced traceback from: %s:%s",
called_from.f_code.co_filename, called_from.f_lineno)
logger.error("Reproduced traceback from: %s:%s",
called_from.f_code.co_filename, called_from.f_lineno)
for line in tb_info(exc_info):
for l in line.splitlines():
log.error(l)
log.error('')
logger.error(l)
logger.error('')
def log_message(message, logger=''):
......@@ -50,11 +51,12 @@ def log_message(message, logger=''):
Log message to logger.
:param message: Message
:param logger: Name of the logger (defaults to '')
:param logger: Name or logger instance (defaults to '')
"""
log = logging.getLogger(logger)
if isinstance(logger, basestring):
logger = logging.getLogger(logger)
for line in message.splitlines():
log.error(line)
logger.error(line)
def analyze_unpickable_item(path_prefix, obj):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册