Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Logging to a file and closing it again properly (logging module)

Thread Tools

Logging to a file and closing it again properly (logging module)

Christoph Haas
Posts: n/a

I have an application that is running in an endless loop processing an
incoming queue. Every run is supposed to write a log file about the run
and then close it again. While the 'logging' module is generally working
well (even though the documentation makes me miss some proper examples
how everything works together) I can't seem to close the log file again
to open a new one.

This is basically what I'm doing:

log = logging.getLogger("myapplication")

Now I'm missing a way to tell this handler to go away. Through 'ipython'
I found out there is a log.handlers array that contains all the
handlers. Perhaps I could delete all of them but I'm sure there is a
more proper way to close files again.

Googling found me:

.>>> logging._handlers.clear()
.>>> logging.root.handlers = []
.>>> for l in logging.Logger.manager.loggerDict.values():
.>>> l.handlers = []

But this looks really really ugly. I don't like to mess with the gears
in the 'logging' module.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing popup window when closing parent window? =?Utf-8?B?Vk1J?= ASP .Net 3 02-15-2007 08:29 AM
Re: Logging to a file and closing it again properly (logging module) Christoph Haas Python 1 06-14-2006 08:47 AM
Closing the doors 15 minutes before closing. doofus Computer Support 12 06-11-2005 08:20 AM
IE 6 not closing properly Ronnie G Computer Support 2 09-02-2004 03:13 PM
More American Graffiti: Properly Framed, Properly Scored? Scot Gardner DVD Video 0 09-02-2003 02:28 AM