python日志记录不释放文件

标签 python python-3.x logging

我一直在使用日志记录,并注意到第一次编译后,用于日志记录的输出文件挂起,并且在关闭 IDLE 之前我无法将其删除。

我相信我应该在编译完成之前“关闭”日志记录,但不知道如何使用我使用日志记录的方式来做到这一点:

LOGFILE = os.path.join(backup_folder,'test.log')
logging.basicConfig(filename=LOGFILE,level=logging.DEBUG,format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
logging.debug('test')

最佳答案

看来我找到了一种方法,在最后添加:

logging.shutdown()

此指令关闭所有打开的处理程序。

关于python日志记录不释放文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45304308/

相关文章:

python - 为什么 mypy 常见问题解答提到性能影响?

python - 在 Python 中从 XML 中获取文本值

python - 在flask html页面中访问json数据

c# - 在 nlog 中以编程方式创建数据库以启用 DatabaseTarget

python - Numpy/Polyfit - 禁止打印英特尔 MKL 错误消息

python - 使用 list(filter()) 的程序在 python 3 上运行速度极慢

python - 尝试在 for 循环之外使用变量会出现 SyntaxError : no binding for nonlocal 'max_' found

Python 类型提示和 linter

android - 如何以简单的方式将 shell 脚本输出重定向到 Logcat

windows - 写入 Windows 安全日志