【发布时间】:2016-05-04 01:14:10
【问题描述】:
我在使用内置记录器模块时遇到了困难。显示警告消息,但不显示信息消息。像这样:
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.info('Info') # This line was inserted.
>>> logging.basicConfig(level=logging.DEBUG)
>>> logging.warning('Warning')
WARNING:root:Warning
>>> logging.info('Info')
>>>
有趣的是,在离开我的办公桌一个小时左右,然后开始新的会话后,我得到了以下结果:
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.basicConfig(level=logging.DEBUG)
>>> logging.warning('Warning')
WARNING:root:Warning
>>> logging.info('Info')
INFO:root:Info
>>>
成功了!问题是为什么第一个版本不起作用。
注意:问题已被编辑。
【问题讨论】:
-
奇怪。如果您没有设置
level=logging.DEBUG参数,那将是预期的行为。它对我有用,正如你所拥有的那样。 -
Thomas 链接中的代码对我有用。使用有效的代码行在下面查看我的答案。
-
仅供参考:PyScripter 中存在一个错误(否则它是一个很好的调试环境),并且在使用推荐的远程 Python 解释器时无法正确显示日志消息。