logging remove / inspect / modify handlers configured by fileConfig()

前端 未结 5 1754
醉梦人生
醉梦人生 2021-02-03 17:10

How can I remove / inspect / modify handlers configured for my loggers using the fileConfig() function?

For removing there is Logger.removeHandler(hdlr) method, but how

5条回答
  •  忘掉有多难
    2021-02-03 17:31

    Another approach might be to use a JSON or YAML config file which gets loaded into a dictionary which you can then view/manipulate before it's passed to the logger.config.

    import yaml
    import logging.config
    
    with open (LOG_CONFIG, 'rt') as f:
       config=yaml.safe_load(f)
       config['handlers']['error_file_handler']['filename']='foo'
    logging.config.dictConfig(config)
    

提交回复
热议问题