[Zope-Checkins] SVN: Zope/trunk/lib/python/ZConfig/components/logger/loghandler.py * Implement a file handler with 'rotate'. This closes the file, attempts

2005-04-13 Thread Sidnei da Silva
Log message for revision 29977:
  
  * Implement a file handler with 'rotate'.  This closes the file, attempts
a rename to {filename}.last, then reopens the original name.  This
then makes the log available for another process to perform the rotation
logic on. This log handler is only installed on the Windows
platform, where you can't rename an open file.
  

Changed:
  U   Zope/trunk/lib/python/ZConfig/components/logger/loghandler.py

-=-
Modified: Zope/trunk/lib/python/ZConfig/components/logger/loghandler.py
===
--- Zope/trunk/lib/python/ZConfig/components/logger/loghandler.py   
2005-04-14 02:01:49 UTC (rev 29976)
+++ Zope/trunk/lib/python/ZConfig/components/logger/loghandler.py   
2005-04-14 02:08:52 UTC (rev 29977)
@@ -13,7 +13,7 @@
 
 Handlers which can plug into a PEP 282 logger.
 
-import os.path
+import os
 import sys
 
 from logging import Handler, StreamHandler
@@ -42,7 +42,28 @@
 self.close()
 self.stream = open(self.baseFilename, self.mode)
 
+class Win32FileHandler(FileHandler):
+File-based log handler for Windows that supports an additional 'rotate'
+method.  reopen() is generally useless since Windows cannot do a move on
+an open file.
+
+def rotate(self, rotateFilename=None):
+if not rotateFilename:
+rotateFilename = self.baseFilename + .last
+error = None
+self.close()
+try:
+os.rename(self.baseFilename, rotateFilename)
+except OSError:
+pass
 
+self.stream = open(self.baseFilename, self.mode)
+
+if os.name == nt:
+# Make it the default for Windows - we install a 'reopen' handler that
+# tries to rotate the logfile.
+FileHandler = Win32FileHandler
+
 class NullHandler(Handler):
 Handler that does nothing.
 

___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins


Re: [Zope-Checkins] SVN: Zope/trunk/lib/python/ZConfig/components/logger/loghandler.py * Implement a file handler with 'rotate'. This closes the file, attempts

2005-04-13 Thread Tim Peters
[Sidnei da Silva]
 Log message for revision 29977:
 
  * Implement a file handler with 'rotate'.  This closes the file, attempts
a rename to {filename}.last, then reopens the original name.  This
then makes the log available for another process to perform the rotation
logic on. This log handler is only installed on the Windows
platform, where you can't rename an open file.
 
 Changed:
  U   Zope/trunk/lib/python/ZConfig/components/logger/loghandler.py

This checkin probably crossed the mail with my msg to you:  Zope trunk
doesn't own ZConfig, and changing ZConfig code from a Zope checkout
has no effect on the real ZConfig code.  So these changes will
probably get lost(*).  You should merge them (if possible) to ZConfig
trunk.

(*) I've spent a lot of time carefully checking checkin msgs for changes to
ZODB checked in from wrong projects, but missed some even so.  I haven't
spend any time looking for checkins to ZConfig or zdaemon made from wrong
projects, and I don't think anyone does.  I noticed this one by pure luck.
___
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins