[Erp5-report] r46039 seb - in /erp5/trunk/utils/Products.LongRequestLogger/Products/LongReq...

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jun 5 11:53:05 CEST 2012


Author: seb
Date: Tue Jun  5 11:53:04 2012
New Revision: 46039

URL: http://svn.erp5.org?rev=46039&view=rev
Log:
Integrate log handleer with Zope's signal handling and ZConfig's reopen/rotate handlers.

Patch coming from ctheune :
http://svn.zope.org/Products.LongRequestLogger/trunk/?rev=124266&view=rev

Added:
    erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/docs/
    erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/docs/HISTORY.txt
Modified:
    erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/dumper.py

Added: erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/docs/HISTORY.txt
URL: http://svn.erp5.org/erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/docs/HISTORY.txt?rev=46039&view=auto
==============================================================================
--- erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/docs/HISTORY.txt (added)
+++ erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/docs/HISTORY.txt [utf8] Tue Jun  5 11:53:04 2012
@@ -0,0 +1,14 @@
+Changelog
+=========
+
+1.1dev (unreleased)
+-------------------
+
+- Integrate the logging mechanism with Zope's signal handling and ZConfig's
+  rotating file handler so that USR2 signals will cause the long request log
+  to get reopened analogous to the access and event log.
+
+1.0
+---
+
+- Initial release

Modified: erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/dumper.py
URL: http://svn.erp5.org/erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/dumper.py?rev=46039&r1=46038&r2=46039&view=diff
==============================================================================
--- erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/dumper.py [utf8] (original)
+++ erp5/trunk/utils/Products.LongRequestLogger/Products/LongRequestLogger/dumper.py [utf8] Tue Jun  5 11:53:04 2012
@@ -1,17 +1,27 @@
 ##############################################################################
 #
-# Copyright (c) 2010 Zope Foundation and Contributors.
+# Copyright (c) 2010,2012 Zope Foundation and Contributors.
 #
 ##############################################################################
 
-import os
-import os.path
-import traceback
-import logging
 from cStringIO import StringIO
+from pprint import pformat
 from thread import get_ident
+import Signals.Signals
+import ZConfig.components.logger.loghandler
+import ZServer.BaseLogger
+import logging
+import os
+import os.path
 import time
-from pprint import pformat
+import traceback
+
+try:
+    from signal import SIGUSR2
+except ImportError:
+    # Windows doesn't have these (but also doesn't care what the exact
+    # numbers are)
+    SIGUSR2 = 12
 
 try:
     from sys import _current_frames
@@ -19,6 +29,7 @@ except ImportError:
     # Python 2.4 and older
     from threadframe import dict as _current_frames
 
+
 class NullHandler(logging.Handler):
     def __init__(self):
         logging.Handler.__init__(self)
@@ -28,8 +39,9 @@ class NullHandler(logging.Handler):
     def emit(self, *args, **kw):
         pass
 
+
 # we might want to change this name later to something more specific
-logger_name = __name__  
+logger_name = __name__
 log = logging.getLogger(logger_name)
 log.propagate = False
 handler = NullHandler()
@@ -46,21 +58,35 @@ def do_enable():
     # The worse that can happen is that a change in longrequestlogger_file
     # will stop or change the logging destination of an already running request
     logfile = os.environ.get('longrequestlogger_file')
-    if logfile:
-        if logfile != 'null':
-            # to imitate FileHandler
-            logfile = os.path.abspath(logfile)
-        if handler.baseFilename != logfile:
-            log.removeHandler(handler)
-            handler.close()
-            if logfile == 'null':
-                handler = NullHandler()
-            else:
-                handler = logging.FileHandler(logfile)
-                handler.formatter = formatter
-            log.addHandler(handler)
-        return log # which is also True as boolean
-    return None # so that Dumpers know they are disabled
+    if not logfile:
+        return None # so that Dumpers know they are disabled
+
+    if logfile != 'null':
+        # to imitate FileHandler
+        logfile = os.path.abspath(logfile)
+
+    rotate = None
+    if handler.baseFilename != logfile:
+        log.removeHandler(handler)
+        handler.close()
+        if logfile == 'null':
+            handler = NullHandler()
+        elif os.name == 'nt':
+            rotate = Signals.Signals.LogfileRotateHandler
+            handler = ZConfig.components.logger.loghandler.Win32FileHandler(
+                logfile)
+        else:
+            rotate = Signals.Signals.LogfileReopenHandler
+            handler = ZConfig.components.logger.loghandler.FileHandler(
+                logfile)
+        handler.formatter = formatter
+        log.addHandler(handler)
+
+    # Register with Zope 2 signal handlers to support log rotation
+    if rotate and Signals.Signals.SignalHandler:
+        Signals.Signals.SignalHandler.registerHandler(
+            SIGUSR2, rotate([handler]))
+    return log # which is also True as boolean
 
 def get_configuration():
     return dict(



More information about the Erp5-report mailing list