首页 > 解决方案 > 日志没有写入文件

问题描述

我在此处使用以下示例,以及来自 Gnu/Linux 虚拟环境的 Python 3.6.5:

import logging
logging.basicConfig(filename='example.log',level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')

我只在标准输出中收到此消息:

WARNING:root:And this, too

没有生成输出文件。

我注意到它适用于 Python 2.7.15。

有任何想法吗?

标签: pythonlinuxpython-3.xlogging

解决方案


推荐阅读