I'm using Python logging.basicConfig method, passing it some arguments including filemode = "w". If it's not specified, it defaults to "a", appending. However, despite specifying it to overwrite the existing log file, it's yet appending.
import logging
# add filemode "w" to overwrite
logging.basicConfig(filename = "sample.log", level = logging.INFO,filemode = "w")
logging.debug("This is a debug message")
logging.info("Informational message")
logging.error("An error has happened!")
Use the below code and try -
filemode = "w+"
logging.basicConfig(filename = "sample.log",
level = logging.INFO,
filemode = "w+" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With