gpt4 book ai didi

Python 2.4.3 : ConfigParser. NoSectionError:无节: 'formatters'

转载 作者:IT老高 更新时间:2023-10-28 20:35:35 25 4
gpt4 key购买 nike

尝试使用日志配置文件来实现TimedRotatinigFileHandler

只是因为某种原因不接受配置文件。

任何建议表示赞赏。


x.py:

import logging
import logging.config
import logging.handlers

logging.config.fileConfig("x.ini")

MyLog = logging.getLogger('x')

MyLog.debug('Starting')

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'

谢谢

最佳答案

错误信息非常准确,但具有误导性。

“格式化程序”部分丢失的原因是日志记录模块找不到您传递给 logging.config.fileConfig 的文件。

尝试使用绝对文件路径。

关于Python 2.4.3 : ConfigParser. NoSectionError:无节: 'formatters',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7922602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com