reset python interpreter for logging -
i new python. i'm using vim python-mode edit , test code , noticed if run same code more once, logging file updated first time code run. example below piece of code called "testlogging.py"
#!/usr/bin/python2.7 import os.path import logging filename_logging = os.path.join(os.path.dirname(__file__), "testlogging.log") logging.basicconfig(filename=filename_logging, filemode='w', level=logging.debug) logging.info('aye')
if open new gvim session , run code python-mode, file called "testlogging.log" content
info:root:aye
looks promising! if delete log file , run code in pythong-mode again, log file won't re-created. if @ time run code in terminal this
./testlogging.py
then log file generated again!
i checked python documentation , noticed line in logging tutorial (https://docs.python.org/2.7/howto/logging.html#logging-to-a-file):
a common situation of recording logging events in file, let’s @ next. sure try following in newly-started python interpreter, , don’t continue session described above:...
so guess problem logging file updated once has python-mode remaining in same interpreter when run code second time. question is: there anyway solve problem, fiddling logging module, putting in code reset interpreter or telling python-mode reset it?
i curious why logging module requires newly-started interpreter work...
thanks in advance.
the log file not recreated because logging module still has old log file open , continue write (even though you've deleted it). solution force logging module release acquired resources before running code again in same interpreter:
# configure logging # log message # delete log file logging.shutdown() # configure logging # log message (log file recreated)
in other words, call logging.shutdown()
@ end of code , can re-run within same interpreter , work expected (re-creating log file on every run).
Comments
Post a Comment