【发布时间】:2018-06-19 10:21:05
【问题描述】:
我正在从 perl (log4perl) 和 java (slf4j) 移植一些代码。一切都很好,除了 logging.critical() 不会像在其他框架中那样转储堆栈跟踪并死掉,需要添加很多额外的代码,logger.exception() 也只会写入错误。
今天我这样做:
try:
errmsg = "--id={} not found on --host={}".format(args.siteid, args.host)
raise GX8Exception(errmsg)
except GX8Exception as e:
log.exception(e)
sys.exit(-1)
这会产生:
2018-01-10 10:09:56,814 [ERROR ] root --id=7A4A7845-7559-4F89-B678-8ADFECF5F7C3 not found on --host=welfare-qa
Traceback (most recent call last):
File "./gx8-controller.py", line 85, in <module>
raise GX8Exception(errmsg)
GX8Exception: --id=7A4A7845-7559-4F89-B678-8ADFECF5F7C3 not found on --host=welfare-qa
有没有办法配置 pythonmodule logger 来做到这一点,或者任何其他框架来做同样的事情:
log.critical("--id={} not found on --host={}".format(args.siteid, args.host))
【问题讨论】:
标签: python-3.x logging exception-handling