這裏轉換期間的所有參數是我在做什麼的Python:登錄類型錯誤:不是字符串格式化
>>> import logging
>>> logging.getLogger().setLevel(logging.INFO)
>>> from datetime import date
>>> date = date.today()
>>> logging.info('date={}', date)
Traceback (most recent call last):
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 846, in emit
msg = self.format(record)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 723, in format
return fmt.format(record)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 464, in format
record.message = record.getMessage()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 328, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
Logged from file <stdin>, line 1
>>>
我的Python版本
$ python --version
Python 2.7.3
我如何工作的呢?
知道,通過執行格式化自己,你失去通過讓記錄模塊所提供的速度優勢爲你做*只有當消息實際記錄*。換句話說,如果您使用'debug()'處理程序,但日誌記錄級別不包含DEBUG級別,則不會招致字符串格式化操作的損失。如果您有很多調試消息,則速度差異可能很大。 –