Python 3.4日志记录配置
我想将我当前的项目从python 2.7转换为3.5。首要任务之一是配置日志记录。我使用灵活的配置文件,日期是文件名的一部分。 以下是设置了文件处理程序,在2.7Python 3.4日志记录配置
[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=simpleFormatter
# Only one log per day will be created. All messages will be appended to it.
args=("D:\\Logs\\PyLogs\\" + time.strftime("%Y%m%d%H%M%S")+'.log', 'a')
工作正常在3.5出现以下错误代码:
configparser.InterpolationSyntaxError: '%' must be followed by '%' or '(', found: '%Y%m%d%H%M%S")+\'.log\', \'a\')'
有没有人经历这件事?有没有更好的方式来格式化配置文件中的日期?
主题类似这个帖子: Configparser and string with %
我想你可能需要%
我看了之前,它没有提供任何帮助 –
加倍'%'没有解决它? –
其实它修正了它。 我没有尝试过,因为我认为它只是将问题从configparser转换为time.strftime。 –
替代我很惊讶这个工作都在2.7。为什么不使用['TimedRotatingFileHandler'](https://docs.python.org/3/library/logging.handlers.html#timedrotatingfilehandler)? 'class = TimedRotatingFileHandler',用'when ='D'。 –
我没有使用TimeRotatingFileHandler,因为它没有做我想要的,但谢谢你的建议。 –