小编Moj*_*van的帖子

pythonlogging.basicConfig 不会覆盖现有的日志文件

我正在使用 Pythonlogging.basicConfig方法,向其传递一些参数,包括filemode = "w". 如果不指定,则默认为"a", 追加。但是,尽管指定它覆盖现有日志文件,但它仍在附加。

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!")
Run Code Online (Sandbox Code Playgroud)

python logging overwrite python-3.x

3
推荐指数
1
解决办法
3258
查看次数

标签 统计

logging ×1

overwrite ×1

python ×1

python-3.x ×1