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 自版本2.5以来日志记录的更改_Python_Logging - Fatal编程技术网

Python 自版本2.5以来日志记录的更改

Python 自版本2.5以来日志记录的更改,python,logging,Python,Logging,我使用python日志模块已经有一段时间了,但最近在测试与较旧python版本的兼容性时遇到了一些问题: Traceback (most recent call last): File "hunter.py", line 16, in <module> logging.config.fileConfig("logging.conf") File "/usr/lib/python2.5/logging/config.py", line 85, in fileConfig

我使用python日志模块已经有一段时间了,但最近在测试与较旧python版本的兼容性时遇到了一些问题:

Traceback (most recent call last):
  File "hunter.py", line 16, in <module>
    logging.config.fileConfig("logging.conf")
  File "/usr/lib/python2.5/logging/config.py", line 85, in fileConfig
    _install_loggers(cp, handlers)
  File "/usr/lib/python2.5/logging/config.py", line 229, in _install_loggers
    logger.addHandler(handlers[string.strip(hand)])
KeyError: 'hunterFileHandler'

有没有一种简单的方法可以使配置向后兼容,而不复制大部分配置?

您的问题很可能是由此行中的空格引起的:

keys=consoleHandler, hunterFileHandler
                    ^
由于2.5中的错误,不会跳过前导空格,并且会出现
键错误
,因为该键未正确设置为
“hunterFileHandler”
。如果你把这行改成

keys=consoleHandler,hunterFileHandler
然后文件应该正确加载


但是,您应该注意到,在2.5和2.6中修复了几个bug,因此您可能会被其中一个bug(除了我提到的那个之外)咬到。请参阅jcollado对您的问题的评论。

您的问题很可能是由此行中的空格引起的:

keys=consoleHandler, hunterFileHandler
                    ^
由于2.5中的错误,不会跳过前导空格,并且会出现
键错误
,因为该键未正确设置为
“hunterFileHandler”
。如果你把这行改成

keys=consoleHandler,hunterFileHandler
然后文件应该正确加载

但是,您应该注意到,在2.5和2.6中修复了几个bug,因此您可能会被其中一个bug(除了我提到的那个之外)咬到。请参阅jcollado对您的问题的评论。

看起来这可能对您的问题有用。看起来这可能对您的问题有用。