Python logging file config KeyError: 'formatters'

后端 未结 4 1739
生来不讨喜
生来不讨喜 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 08:59

    I had this issue because Python couldn't find my config file, though you would never know it by the error message. Apparently it does not look for the config file relative to the file in which the code is running, but rather relative to the current working directory (which you can get from os.getcwd()). I used the following code to initialize the logger. The log.config file is in the same directory as the file running this code:

    from os import path
    log_file_path = path.join(path.dirname(path.abspath(__file__)), 'log.config')
    logging.config.fileConfig(log_file_path)
    

提交回复
热议问题