gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:06:49 24 4
gpt4 key购买 nike

当我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com