Python logging file config KeyError: 'formatters'

后端 未结 4 1744
生来不讨喜
生来不讨喜 2021-02-02 08:45

I\'m currently working on a python project and I set up logging using a config file. It has already worked and was logging my messages as wanted.

But then, after rearran

4条回答
  •  攒了一身酷
    2021-02-02 09:04

    d512 was correct. And when running the code and based on the PYTHONPATH, Python treats your project root directory as the 'current path' no matter where is your running file located. So another way is to add the relative path either as following:

    logging.config.fileConfig('root_path_of_project/.../logging.conf')
    

    or relative to the current file:

    LOGGING_CONFIG = Path(__file__).parent / 'logging.conf'
    ...
    logging.config.fileConfig(LOGGING_CONFIG)
    

    Hope it helps

提交回复
热议问题