[Zope-dev] Log rotation on Windows
alangmead at boston.com
Tue Jan 25 13:59:42 EST 2005
On Jan 24, 2005, at 8:12 PM, Mark Hammond wrote:
> A number of Enfold's customers have requested a reasonable logfile
> scheme for Zope on Windows. Enfold would like to work on this and
> contribute it back to Zope. The intention of this mail is to find a
> consensus on the general solution we should adopt, so we can supply
> with the greatest chance of getting into the core.
Since ZConfig and zLOG are both designed to be extensible. They are
built so that new loggers can be created without any changes to the
Zope core. It seems to me that most of this could be handled by an
add-on package. The ZConfig documentation
has as its extension example how to add a new logger (a "log to a
pager" logger) to the system. (Of course once this is built, this
add-on package could migrate to the core if there is a compelling need,
either packaging convenience (Windows users don't need to grab an extra
package to manage their systems well.) or so that enhancements to
zLOG's loghandlers can keep the win32 loggers in mind.)
As a rough cut, this will create a logger with a logrotate behavior
similar to what you are looking for.
# empty file to signify a package.
<!-- extend the logging subsystem with a new file logger -->
<sectiontype name="win32-logfile" datatype=".Win32FileHandlerFactory"
<key name="rotate-path" required="yes"/>
"""" A file based loghandler that renames on rotate """
def __init__(self, path, rotate_path):
self.rotateFilename = rotate_path
error = None
except OSError, err:
error = err
self.stream = open(self.baseFilename, self.mode)
zLOG.LOG("Win32Logger", zLOG.ERROR, "Rotate Error", error)
and then adjust the zope.conf with:
Of course, it needs to be fleshed out with better error handling, etc.
Although time consuming, maybe the better behavior would be to have the
reopen method copy the current log to the backup file and then seek()
and truncate() the original file. That would take longer to rotate, but
would protect against log files whose close() succeed but open() fails.
More information about the Zope-Dev