Can I get logging.FileHandler to close the file on each emit?
Mark Lawrence
breamoreboy at yahoo.co.uk
Wed Aug 29 08:49:33 EDT 2012
On 29/08/2012 11:18, rikardhulten at gmail.com wrote:
> I use logging.FileHandler (on windows) and I would like to be able to delete the file while the process is running and have it create the file again on next log event.
>
> On windows (not tried linux) this is not possible because the file is locked by the process, can I get it to close the file after each log event?
>
> If not, would the correct thing to do be to write my own LogHandler with this behavior?
>
> / Rikard
>
I know little about the logging module but given that the FileHandler[1]
has a close method, can you simply call that, delete the file and reopen
where needed? Failing that I'd look at subclassing existing code and
not writing your own (Your wording implies to me that you're thinking of
writing something from scratch, my apologies should I be wrong on that).
[1] http://docs.python.org/dev/library/logging.handlers.html
--
Cheers.
Mark Lawrence.
More information about the Python-list
mailing list