python - Google Colab 中的日志记录模块问题

标签 python logging error-handling jupyter-notebook google-colaboratory

我有一个使用 logging 模块进行错误处理的 python 脚本。尽管此 python 脚本在导入到 google colab 时有效,但它不会在日志文件中记录错误。

作为实验,我在 google colab 中尝试了以下脚本,只是为了查看它是否完全写入日志

import logging
logging.basicConfig(filename="log_file_test.log",
                            filemode='a',
                            format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
                            datefmt='%H:%M:%S',
                            level=logging.DEBUG)

logging.info("This is a test log ..")

令我沮丧的是,它 甚至没有创建 一个名为 的日志文件log_file_test.log .我尝试运行相同的脚本 本地 确实产生了一个文件 log_file_test.log 带有以下文字

13:20:53,441 root INFO This is a test log ..



我在这里想念什么?
目前,我正在用打印语句替换错误日志,但我认为必须有一个解决方法。

最佳答案

也许您已经以某种方式重新配置了您的环境? (尝试运行时菜单-> 重置所有运行时...)您的代码片段与为我编写的完全一样——

enter image description here

关于python - Google Colab 中的日志记录模块问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54597462/

相关文章:

python - 在 Python 中拆分文本

python - Scrapy 表示没有抓取任何页面/项目?

exception - 在哪里捕获此错误?

python - 使用 Python 和 Flask 返回 API 错误消息

python - 是否有不能用关键字参数调用的内置函数的完整列表?

python - 了解Python文档: how to know what a function returns?

c++ - 使此代码线程安全的最有效方法是什么?

scala - 尝试使用异常日志记录

spring - SimpleMappingExceptionResolver-异常不显示给 View

python - pandas 按另一列的平均值对一列的值进行排序