i was able to fix the exception by calling logging.shutdown() before the call to os.remove().
However, I still think there is probably a more elegant solution. On Wed, Jan 6, 2010 at 12:57 PM, Chris Colbert <sccolb...@gmail.com> wrote: > 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. > > The problem I am running into is that the stdlib logging module creates the > log file immediately upon logger instantiation. > > Thus: > >>> logger = logging.basicConifg('testlog.txt') > > already creates the file 'testlog.txt'. > > 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. > > 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. > > Thanks for any pointers! > > Chris >
-- http://mail.python.org/mailman/listinfo/python-list