从 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")
通过创建一个日志系统来做基本的配置带有默认格式化程序的 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.
如果根记录器已经有处理程序,这个函数什么都不做为它配置.
似乎 ipython notebook 在某处调用了 basicConfig(或设置处理程序).
It seems like ipython notebook call basicConfig (or set handler) somewhere.
这篇关于从 IPython Notebook 中的日志记录模块获取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!