从IPython Notebook中的日志记录模块获取输出 [英] Get Output From the logging Module in IPython Notebook
问题描述
当我在IPython Notebook中运行以下命令时,我看不到任何输出:
When I running the following inside IPython Notebook I don't see any output:
import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug("test")
任何人都知道如何做到这一点,这样我就可以在笔记本中看到测试"消息了吗?
Anyone know how to make it so I can see the "test" message inside the notebook?
推荐答案
尝试以下操作:
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logging.debug("test")
根据 logging.basicConfig :
通过创建日志来对日志记录系统进行基本配置 具有默认Formatter的StreamHandler并将其添加到根目录 记录器.函数debug(),info(),warning(),error()和 如果没有处理程序,critical()将自动调用basicConfig() 为根记录器定义的.
Does basic configuration for the logging system by creating a StreamHandler with a default Formatter and adding it to the root logger. The functions debug(), info(), warning(), error() and critical() will call basicConfig() automatically if no handlers are defined for the root logger.
如果root记录器已经具有处理程序,则此功能不执行任何操作 为此进行配置.
This function does nothing if the root logger already has handlers configured for it.
似乎ipython笔记本在某处调用basicConfig(或设置处理程序).
It seems like ipython notebook call basicConfig (or set handler) somewhere.
这篇关于从IPython Notebook中的日志记录模块获取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!