我正在尝试写入
python中的日志;我希望能够从文件加载配置,但我在调用后收到错误:
logging.config.fileConfig(‘logging.conf’)
Traceback (most recent call last):
File “/usr/lib64/python2.4/logging/config.py”, line 157, in fileConfig
log.addHandler(handlers[hand])
KeyError: ‘simpleHandler’
我的配置是:
[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
请帮我确定错误是什么,谢谢.
最佳答案 在你的文件处理程序中试试这个:
[handler_simpleHandler]
formatter=simpleFormatter
class=handlers.RotatingFileHandler
maxBytes=31457280
level=DEBUG
args=('/tmp/test.log',)