Python 2.4.3:ConfigParser.NoSectionError:无部分:'formatters' [英] Python 2.4.3: ConfigParser.NoSectionError: No section: 'formatters'
本文介绍了Python 2.4.3:ConfigParser.NoSectionError:无部分:'formatters'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用日志记录配置文件来实现TimedRotatinigFileHandler
.
Trying to use a logging configuration file to implement TimedRotatinigFileHandler
.
出于某种原因,不会使用配置文件.
Just won't take the config file for some reason.
任何建议表示赞赏.
x.py:
import logging
import logging.config
import logging.handlers
logging.config.fileConfig("x.ini")
MyLog = logging.getLogger('x')
MyLog.debug('Starting')
x.ini:
x.ini:
[loggers]
keys=root
[logger_root]
level=NOTSET
handlers=trfhand
[handlers]
keys=trfhand
[handler_trfhand]
class=handlers.TimedRotatingFileHandler
when=M
interval=1
backupCount=11
formatter=generic
level=DEBUG
args=('/var/log/x.log',)
[formatters]
keys=generic
[formatter_generic]
class=logging.Formatter
format=%(asctime)s %(levelname)s %(message)s
datefmt=
Traceback (most recent call last):
File "x.py", line 5, in ?
logging.config.fileConfig("x.ini")
File "/usr/lib/python2.4/logging/config.py", line 76, in fileConfig
flist = cp.get("formatters", "keys")
File "/usr/lib/python2.4/ConfigParser.py", line 511, in get
raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'formatters'
谢谢
推荐答案
该错误消息严格准确,但却具有误导性.
The error message is strictly accurate but misleading.
缺少格式器"部分的原因是因为日志记录模块找不到您传递给logging.config.fileConfig
的文件.
The reason the "formatters" section is missing, is because the logging module can't find the file you passed to logging.config.fileConfig
.
尝试使用绝对文件路径.
Try using an absolute file path.
这篇关于Python 2.4.3:ConfigParser.NoSectionError:无部分:'formatters'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文