【发布时间】:2016-06-03 12:42:57
【问题描述】:
如果我运行以下代码:
import logging
logger = logging.getLogger('creator')
try:
# some stuff
except Exception as exception:
logger.exception(exception)
我在屏幕上得到以下输出:
creator : ERROR division by zero
Traceback (most recent call last):
File "/graph_creator.py", line 21, in run
1/0
ZeroDivisionError: division by zero
有没有办法得到这样的输出?
creator : ERROR ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/graph_creator.py", line 21, in run
1/0
当然,我可以得到这个(但我不喜欢它):
creator : ERROR Сaught exception (and etc...)
Traceback (most recent call last):
File "/graph_creator.py", line 21, in run
1/0
ZeroDivisionError: division by zero
【问题讨论】:
-
看到您的评论。您需要采用自定义的
Formatter方法。
标签: python exception logging exception-handling output