python logging file is not working when using logging.basicConfig

前端 未结 5 703
一生所求
一生所求 2021-01-31 08:01

I have the following lines of code that initialize logging. I comment one out and leave the other to be used. The problem that I\'m facing is that the one that is meant to log t

5条回答
  •  青春惊慌失措
    2021-01-31 08:15

    I got the same error, I fixed it by passing the following argument to the basic config.

    logging.basicConfig(
        level="WARNING",
        format="%(asctime)s - %(name)s - [ %(message)s ]",
        datefmt='%d-%b-%y %H:%M:%S',
        force=True,
        handlers=[
            logging.FileHandler("debug.log"),
            logging.StreamHandler()
        ])
    

    Here as you can see passing force=True overrides any other BasicConfigs

提交回复
热议问题