【发布时间】:2017-07-10 16:46:11
【问题描述】:
我正在尝试学习 python 中的日志记录,并尝试运行 Python 2.7 文档提供的基本程序。但是 python 记录器甚至没有创建文件。所以我自己在目录中创建了文件,但现在记录器没有将任何内容记录到日志文件中。这是我的代码:
import logging
logging.basicConfig(filename='C:/Users/nippo1994/Documents/PythonScripts/checkstry.log',level=logging.debug,format='%(levelname)s %(asctime)s ::%(message)s',)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
更新 1
代码适用于 python 3.x.x 但不适用于 Python 2.7,有人可以指导我为什么 python 会出现这种奇怪的行为吗?
更新 2 它似乎是 Spyder 2.7 中的一个问题,不知道这会产生如此大的不同。附上相同https://github.com/spyder-ide/spyder/issues/2572的链接
【问题讨论】:
标签: python python-2.7 logging spyder