Python logging creates empty files -


i using python's logging facility. simple stuff really, want log file created if there log. in other words, no log file should created if there nothing log.

as my

logging.basicconfig( filename=filename_log, level=logging.debug, mode='w') 

is ran, empty log file created. trying delete before exiting

if ( os.stat( filename_log ).st_size == 0 ): os.remove( filename_log) 

gives error message: "windowserror: [error 32] process cannot access file because being used process". suppose else should done before.

so, way not have empty log files generated, without writing own logging procedure?

thanks.


edit:

in short:

logging.basicconfig( filename=filename_log, level=logging.debug, mode='w') logging.debug('this message should go log file') 

does log gives empty file there nothing logged. and

with open( filename_log, 'w') logfile:     logging.basicconfig( stream=logfile, level=logging.debug) 

gives a: "valueerror: i/o operation on closed file"

i'm not familiar way windows handles i/o. on *nix system suggest i/o stream not closed logging function handles it.

logging.basicconfig( filename=filename_log, level=logging.debug, mode='w')  ... logging.shutdown() if os.stat(file_name).st_size == 0 :      os.remove(filename_log) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -