如何在使用python删除VS代码后自动生成日志文件



我有这个代码来在VS code中生成日志文件。

import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')

然后,我删除了example.log文件,认为每次运行代码时它都会自动生成。但现在,我无法生成日志文件。所以,我想知道如何用这些代码生成日志。这里的问题是什么?

这应该能在中工作

logging.basicConfig( handlers=[ logging.FileHandler('logs.log') ], level=logging.INFO)

最新更新