python - 从 IPython Notebook 中的日志记录模块获取输出

标签 python logging jupyter-notebook jupyter

当我在 IPython Notebook 中运行以下命令时,我看不到任何输出:

import logging
logging.basicConfig(level=logging.DEBUG)
logging.debug("test")

有人知道怎么做,这样我就可以在笔记本中看到“测试”消息了吗?

最佳答案

尝试以下操作:

import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logging.debug("test")

根据logging.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.

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/

相关文章:

c++ - 为 Boost.Log 严重性记录器实例的接收器设置严重性过滤器

python - 朱皮特 : Why does this second command stop the first one from working?

Python-VTK 3D Spline Regression 通过血管树的 STL 模型

docker - 如何启用将Influxdb登录到Docker中的文件

python - 从 Python 中的字母数字字符串列表中执行降序数字排序,然后升序字母排序

java - 使用 java.util.logging.Logger 时如何在文本文件中写入日志

python - Keras tensorflow 已经存在错误?

google-drive-api - google colaboratory 不刷新驱动器内容?

python - innosetup 创建的可执行文件中出现 "Failed to execute script"错误

python - 拆分单元格中具有多个值的行并将其追加回数据列表