【发布时间】:2020-08-08 20:17:17
【问题描述】:
我正在使用 python 的 logging.basicConfig 方法,向它传递一些参数,包括 filemode = "w"。如果未指定,则默认为“a”,追加。但是,尽管指定它来覆盖现有的日志文件,它仍然是附加的。我在 anaconda 上使用 python 3。任何帮助表示赞赏:)
import logging
# add filemode "w" to overwrite
logging.basicConfig(filename = "sample.log", level = logging.INFO,filemode = "w" )
logging.debug("This is a debug message")
logging.info("Informational message")
logging.error("An error has happened!")```
【问题讨论】:
-
我试过你的代码,对我来说很好,当
filemode = "w"时它会覆盖日志文件 -
一天后我一次又一次地尝试,但没有发生任何新情况。它一直在附加。最后我把日志部分扔掉了!
标签: python python-3.x logging anaconda overwrite