gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:06:32 27 4
gpt4 key购买 nike

我有一个使用 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/

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