【发布时间】:2014-03-21 04:50:14
【问题描述】:
这是我在 Python 3.3.2 下运行的一些代码:
import logging
logger = logging.getLogger("test.logger")
logging.getLogger().setLevel(logging.DEBUG) # Shouldn't be needed
logger.setLevel(logging.DEBUG)
print("Effective logging level is {}".format(logger.getEffectiveLevel()))
logger.debug("This is a debug-level message.")
这是输出:
Effective logging level is 10
所以调试消息没有被写入,尽管记录器的级别似乎是正确的。我在 Python 文档或此站点上没有看到任何表明我遗漏任何内容的内容。这里发生了什么?谢谢。
编辑:如果我通过添加此行来锻炼根记录器...
logging.debug("Try this")
...然后两条消息都出来了。 (注意使用logging 而不是logger。)好奇和好奇。
【问题讨论】: