Python logger: won't overwrite the original log?

后端 未结 3 1116
谎友^
谎友^ 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:19

    The mode is specified as part of logging.basicConfig and is passed through using filemode.

    logging.basicConfig(
        level = logging.DEBUG,
        format = '%(asctime)s %(levelname)s %(message)s',
        filename = 'oneDayFileLoader.log,
        filemode = 'w'
    )
    

    https://docs.python.org/3/library/logging.html#simple-examples

提交回复
热议问题