我使用 configparser 读取应用程序的一些配置选项,并且我还想读取日志记录配置。
我可以在同一个文件中执行此操作吗? 我应该如何命名日志记录的特定部分?
最佳答案
由于 @chepner 的建议有所帮助,我将回答我自己的问题。
考虑到 python documentation ,我可以将 configparser.ConfigParser 创建的对象作为参数传递给logging.config.fileConfig 函数
这是截图:
config = configparser.ConfigParser()
config['general'] = {'default-option': 'blah'}
config.read(configFile)
# Logging configuration
logging.config.fileConfig(config, disable_existing_loggers=False)
关于python - 将日志记录配置包含在 configparser 读取的文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26699581/