Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:记录器无法记录对象_Python_Logging - Fatal编程技术网

Python:记录器无法记录对象

Python:记录器无法记录对象,python,logging,Python,Logging,以下是记录器配置 APPLICATION_NAME = 'myapp' # -- setting up global logger - # logger = logging.getLogger(APPLICATION_NAME) logger.setLevel(logging.DEBUG) fh = logging.FileHandler(APPLICATION_NAME + '.log') formatter = logging.Formatter('%(asctime)s - %(na

以下是记录器配置

APPLICATION_NAME = 'myapp'

# -- setting up global logger - #
logger = logging.getLogger(APPLICATION_NAME)
logger.setLevel(logging.DEBUG)

fh = logging.FileHandler(APPLICATION_NAME + '.log')

formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(messages)s')
fh.setFormatter(formatter)

logger.addHandler(fh)
下面是我如何使用它

logger.debug('added transaction: %s', str(transaction))
其中,
事务
是一个实体,
报告
如下所示

def __repr__(self):
    return '<Transaction:%s:%s:%s:%s:%s:%s:%s>' % (
        self.uuid, self.name, self.created_on, self.amount,
        'debit' if self.debit else 'credit', self.user, self.category)
我在这里没有做什么?

应该是
%(消息)s
,而不是
%(消息)s

请参阅文档中的

Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 842, in emit
    msg = self.format(record)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 719, in format
    return fmt.format(record)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/logging/__init__.py", line 467, in format
    s = self._fmt % record.__dict__
KeyError: 'messages'
Logged from file transaction_manager.py, line 30