I use configparser to read some configuration options for my application and I'd like to read the logging configuration as well.
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.
Considering the python documentation , I could just pass the object the configparser.ConfigParser
creates as argument to the logging.config.fileConfig
function
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.