Python logger: won't overwrite the original log?

后端 未结 3 1117
谎友^
谎友^ 2021-01-25 11:59

So, when I copy paste the following x times to the python prompt, it add the log x times to the end of the designated file.

How can I change the code so that each ti

3条回答
  •  感情败类
    2021-01-25 12:34

    Your log messages are being duplicated because you call addHandler more than once. Each call to addHandler adds an additional log handler.

    If you want to make sure the file is created from scratch, add an extra line of code to remove it:

    os.remove(os.path.join(paths["work"], "oneDayFileLoader.log"))
    

提交回复
热议问题