I'm writing to log file using the following code:
import logging
from gmplot import gmplot
logging.basicConfig(filename="sample.log", level=logging.INFO)
logging.debug("This is a debug message")
logging.info("Informational message")
logging.error("An error has happened!")
But then it's impossible to delete this file. how can I 'release' this file?
You need to close() your logging:
As explained there: python does not release filehandles to logfile
When your Run class completes, call:
handlers = self.log.handlers[:]
for handler in handlers:
handler.close()
self.log.removeHandler(handler)
simply use logging.shutdown(), when you are done with logging.
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