【发布时间】:2021-04-24 10:50:01
【问题描述】:
我正在使用 python 的日志记录模块。对于配置,我正在尝试创建一个 yaml 格式的配置文件。但我收到错误
ValueError: Unable to configure handler 'file_handler': __init__() got an unexpected keyword argument 'propagate'
而我可以使用它logger.propagate = False。
我正在关注python logging yaml config,他们使用了相同的配置并能够解析它。
这就是我的 yaml 的样子
version: 1
formatters:
simple:
format: "%(asctime)s %(funcName)s %(levelname)s %(message)s"
handlers:
console:
class: logging.StreamHandler
level: INFO
formatter: simple
file_handler:
class: logging.FileHandler
level: INFO
filename: test_{}.log
formatter: simple
propagate: False
loggers:
dev:
handlers: [console, file_handler]
test:
handlers: [file_handler]
root:
handlers: [file_handler]
这是我遇到的错误
File "/usr/lib/python3.6/logging/config.py", line 565, in configure
handler = self.configure_handler(handlers[name])
File "/usr/lib/python3.6/logging/config.py", line 738, in configure_handler
result = factory(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'propagate'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "logging_manager.py", line 34, in <module>
LoggingManager()
File "logging_manager.py", line 24, in __init__
logging.config.dictConfig(config)
File "/usr/lib/python3.6/logging/config.py", line 802, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python3.6/logging/config.py", line 573, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'file_handler': __init__() got an unexpected keyword argument 'propagate'
我在这里错过了什么?
编辑: 我正在使用环境
Python 3.6.9 (default, Oct 8 2020, 12:12:24)
[GCC 8.4.0] on linux
【问题讨论】:
-
Python 3.6.9 (default, Oct 8 2020, 12:12:24) [GCC 8.4.0] on linux