我有一个使用 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 ..
我在这里想念什么?
目前,我正在用打印语句替换错误日志,但我认为必须有一个解决方法。
最佳答案
关于python - Google Colab 中的日志记录模块问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54597462/