我正在使用以下代码将日志写入文件:
import logging
from gmplot import gmplot
logging.basicConfig(filename="sample.log", level=logging.INFO)
logging.debug("This is a debug message")
logging.info("Informational message")
logging.error("An error has happened!")
但是现在无法删除这个文件。我该如何“释放”这个文件呢?
handlers
为空,则将第一个self.log
替换为logging.getLogger()
,而不是logging.getLogger(__name__)
。 - Nixinova