[Python-Dev] Logging enhancements

Mark Hammond mhammond at skippinet.com.au
Tue Jan 10 09:10:06 CET 2006


Shane:
> Vinay Sajip wrote:

> > I'd be interested in your approach to solve this.
>
> To be compatible with an external tool like logrotate, all a daemon
> needs to do is close and reopen log files at about the same time log
> rotation happens.  To handle this use case, I suggest the logging module
> needs a function named reopen(), which daemons can call upon receipt of
> a signal.  The reopen function will find all handlers with open files
> and ask them to reopen.

FWIW, such an operation is generally useless on a Windows system, as a file
can not be renamed while it is in use.

zope-dev went through this discussion recently, and in the interests of
still allowing an external tool (similar to logrotate) to have the rotation
logic instead of Python or Zope, we came up with a slightly different scheme
for Windows; when requested, Zope will temporarily close the file and rename
it to the original name + ".last" (ignoring any errors.)  It then reopens
the original name.  In most cases, this will leave a .last file around which
can be processed by an external tool, but is also safe in the face of
failure.

IMO, we should consider implementing something like the above; it is still
preferable to have a standard solution for Windows, even if different than
other platforms, rather than requiring everyone to solve this problem
themselves.  I'd even suggest sticking with the name 'reopen()' is still OK,
noting the differences in the documentation, but that is a secondary issue.

Cheers,

Mark



More information about the Python-Dev mailing list