I have an application the writes to a log file when specific exceptions are handled. However, if no exceptions are encountered, I don't want to create a log at all. <br><br>The problem I am running into is that the stdlib logging module creates the log file immediately upon logger instantiation.<br>
<br>Thus:<br>>>> logger = logging.basicConifg('testlog.txt')<br><br>already creates the file 'testlog.txt'. <br><br>So, at program close, I am reading the size of the log file, and if it is empty I remove it with os.remove(). This works fine on Linux, but throws a permission denied exception on Windows. <br>
<br>There has to be a better way to do this than using a hack like that. Is there a way to make the logging module hold-off on file creation until the first log is generated? I could do it by wrapping logger in a class, but that would remove the beauty of having any module import logging from the stdlib and being able to write to the log. <br>
<br>Thanks for any pointers!<br><br>Chris<br>