i was able to fix the exception by calling logging.shutdown() before the call to os.remove().<div><br></div><div>However, I still think there is probably a more elegant solution.<br><br><div class="gmail_quote">On Wed, Jan 6, 2010 at 12:57 PM, Chris Colbert <span dir="ltr"><<a href="mailto:sccolbert@gmail.com">sccolbert@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">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><font color="#888888"><br>Chris<br>
</font></blockquote></div><br></div>