What I want: My python script runs, output logging messages to both the console and to a file.
Once the python script finishes running, I want to be able to delete/edit the logging file. I am using Spyder IDE on Windows7.
Example code:
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
hdlr = logging.FileHandler("/Users/mds/Dropbox/_python/logger-debug.txt")
logger.addHandler(hdlr)
logger.error("Am I duplicating error entries?")
hdlr.close()
Problems I'm having:
After the script finishes running, there is still a lock on the file
Each time I run the script the log file grows many duplicate entries.
first time I run the script:
console:
runfile('C:/Users/mds/Dropbox/_python/logger-debugger.py', wdir='C:/Users/mds/Dropbox/_python')
ERROR:__main__:Am I duplicating error entries?
logger-debug.txt:
Am I duplicating error entries?
Second time I run the script: console:
runfile('C:/Users/mds/Dropbox/_python/logger-debugger.py', wdir='C:/Users/mds/Dropbox/_python')
ERROR:__main__:Am I duplicating error entries?
logger-debug.txt
Am I duplicating error entries?
Am I duplicating error entries?
Am I duplicating error entries?
third time I run the script:
console:
runfile('C:/Users/mds/Dropbox/_python/logger-debugger.py', wdir='C:/Users/mds/Dropbox/_python')
ERROR:__main__:Am I duplicating error entries?
logger-debug.txt
Am I duplicating error entries?
Am I duplicating error entries?
Am I duplicating error entries?
Am I duplicating error entries?
Am I duplicating error entries?
Am I duplicating error entries?