Two questions about logging

Vinay Sajip vinay_sajip at yahoo.co.uk
Sun Jan 15 20:03:08 EST 2012


On Jan 12, 2:19 am, Matthew Pounsett <matt.pouns... at gmail.com> wrote:

> First, I'd like to be able to permit users to do more typical log
> rotation, based on their OS's log rotation handler, rather than
> rotating logs from inside an application.  This is usually handled by
> signalling an application with a HUP, whereupon it closes and then re-
> opens all of its logs, getting new file handles (and new inodes).  I
> don't see anything in the Handler methods (or anywhere else) that
> would let me tell a logger object to refresh the file handles on a log
> file.  Is there some standard way to deal with this?

There's the WatchedFileHandler, which checks to see if a file's device
or inode has changed (which happens when the external rotator does
rotation) and if so, closes and reopens the file. (This handler is for
Unix/Linux/OS X - it doesn't work on Windows).

See

http://docs.python.org/library/logging.handlers.html#watchedfilehandler

for more information.

Regards,

Vinay Sajip



More information about the Python-list mailing list