当我在 IPython Notebook 中运行以下命令时,我看不到任何输出:
import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug("test")
有人知道怎么做,这样我就可以在笔记本中看到“测试”消息了吗?
最佳答案
尝试以下操作:
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logging.debug("test")
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.
This function does nothing if the root logger already has handlers configured for it.
似乎 ipython 笔记本在某处调用了 basicConfig(或设置处理程序)。
关于python - 从 IPython Notebook 中的日志记录模块获取输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18786912/