简体   繁体   English

将日志记录配置包含在configparser读取的文件中

[英]Include logging configuration in file read by configparser

I use configparser to read some configuration options for my application and I'd like to read the logging configuration as well. 我使用configparser来读取我的应用程序的一些配置选项,我也想读取日志记录配置。

Can I do that in the same file? 我可以在同一文件中这样做吗? How should I name the logging specific sections? 我应该如何命名特定于日志的部分?

I'll answer my own question since the advice from @chepner helped. 我会回答我自己的问题,因为@chepner的建议有所帮助。

Considering the python documentation , I could just pass the object the configparser.ConfigParser creates as argument to the logging.config.fileConfig function 考虑到python文档 ,我可以将configparser.ConfigParser创建的对象作为参数传递给logging.config.fileConfig函数

Here is the snipper: 这是抢夺者:

config = configparser.ConfigParser()
config['general'] = {'default-option': 'blah'}
config.read(configFile)
# Logging configuration
logging.config.fileConfig(config, disable_existing_loggers=False)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM