【发布时间】:2017-06-20 19:16:21
【问题描述】:
我正在尝试将变量“log_location”的内容添加到当前记录器。
log_location = log_folder_location + os.path.sep + log_file_name
logger.debug("log location", str(log_location))
print "log_location: ",log_location
这会打印到控制台,但会在日志记录中出错,
Traceback (most recent call last):
File "/usr/lib64/python2.6/logging/__init__.py", line 784, in emit
msg = self.format(record)
File "/usr/lib64/python2.6/logging/__init__.py", line 662, in format
return fmt.format(record)
File "/usr/lib64/python2.6/logging/__init__.py", line 444, in format
record.message = record.getMessage()
File "/usr/lib64/python2.6/logging/__init__.py", line 314, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
打印到,
log_location: /U01/Nova/Logs/DEV-INT/TEST/validation_20170203-164617-5.log
当我在正常的 python 提示符下尝试时,不会发生此错误 但在使用 Flask 时面临同样的问题
我试过Logging Python stdout to File... with active stdout (backspacing/updating) 和TypeError: not all arguments converted during string formatting python 还有这个Python: Logging TypeError: not all arguments converted during string formatting
但不明白该怎么做。有人可以使用更简单的语言来解释这一点,而不是像文档那样吗?
【问题讨论】:
-
您使用的是哪个 Python 版本?也许有unicode问题? log_folder_location 和 log_file_name 是什么类型?
-
我需要您的记录器设置,这可能会有所帮助。