Python logging: Why is __init__ called twice?

后端 未结 2 1612
予麋鹿
予麋鹿 2021-02-07 12:25

I am trying to use python logging with a config file and an own handler. This works to some degree. What really puzzle me is __init__ being called twice and _

2条回答
  •  暖寄归人
    2021-02-07 13:17

    You are missing an if __name__ == "__main__": guard around your logging configuration code. It is getting executed a second time when logging imports your test1 module to find the class reference.

    Alternatively, use the name __main__.Test1TimedRotatingFileHandler in the config file, or else put the configuration code and the handler class in different files.

提交回复
热议问题