2
我一直在使用Python記錄模塊相當長的一段時間,但最近,測試與老的Python版本的兼容性,當我遇到了一些麻煩:變化記錄,因爲2.5版
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'
與以下配置文件(只重要的部分):
[loggers]
keys=root,hunter
[handlers]
keys=consoleHandler, hunterFileHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=DEBUG
handlers=consoleHandler
[logger_hunter]
level=DEBUG
handlers=consoleHandler, hunterFileHandler
qualname=hunter
propagate=0
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)
[handler_hunterFileHandler]
class=handlers.RotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=("logs/hunter.log", "a", 0, 10,)
[formatter_simpleFormatter]
format=%(asctime)s:[%(name)s][%(levelname)5s] %(message)s
datefmt=
有一個簡單的方法,使不重複大部分配置向後兼容?
看起來像這[問題](http://stackoverflow.com/q/1018527/183066)可能對您的問題有用。 – jcollado 2012-01-05 22:01:12