Python日志记录“;“关键错误”;加载fileConfig时
我试图用python编写日志;我希望能够从文件加载配置,但调用以下命令后出现错误: logging.config.fileConfig('logging.conf') 回溯(最近一次呼叫最后一次): 文件“/usr/lib64/python2.4/logging/config.py”,第157行,在fileConfig中 log.addHandler(处理程序[手]) KeyError:“simpleHandler” 我的配置是:Python日志记录“;“关键错误”;加载fileConfig时,python,logging,Python,Logging,我试图用python编写日志;我希望能够从文件加载配置,但调用以下命令后出现错误: logging.config.fileConfig('logging.conf') 回溯(最近一次呼叫最后一次): 文件“/usr/lib64/python2.4/logging/config.py”,第157行,在fileConfig中 log.addHandler(处理程序[手]) KeyError:“simpleHandler” 我的配置是: [loggers] keys=root [hand
[loggers]
keys=root
[handlers]
keys=simpleHandler
[formatters]
keys=simpleFormatter
[logger_root]
level=DEBUG
handlers=simpleHandler
[handler_simpleHandler]
formatter=simpleFormatter
class=handlers.RotatingFileHandler
filename=/tmp/test.log
maxBytes=31457280
level=DEBUG
[formatter_simpleFormatter]
format=%(asctime)s %(levelname)s %(message)s
datefmt=%Y/%m/%d %H:%M:%S
请帮助我确定错误是什么,谢谢。毫无疑问,无论应该在哪个结构中找到键,都缺少键
'simpleHandler'
我建议把你的
handler\u foo
部分放在你的handler
部分之前-看看这是否有帮助。如果这没有帮助,请找到其他方法为您希望的处理程序命名。在您的filehandler中尝试以下方法:
[handler_simpleHandler]
formatter=simpleFormatter
class=handlers.RotatingFileHandler
maxBytes=31457280
level=DEBUG
args=('/tmp/test.log',)
您正在使用Python 2.4版?那太老了!你为什么用这个旧版本?这很有效!从这里的另一篇文章中,我也得到了这一点:
args=('/tmp/test.log','a','maxBytes=31457280','backupCount=15')