[Checkins] SVN: Products.LongRequestLogger/trunk/ Integrate log handleer with Zope's signal handling and ZConfig's reopen/rotate
Christian Theune
ct at gocept.com
Tue Jan 31 10:37:01 UTC 2012
Log message for revision 124266:
Integrate log handleer with Zope's signal handling and ZConfig's reopen/rotate
handlers.
Changed:
U Products.LongRequestLogger/trunk/Products/LongRequestLogger/dumper.py
U Products.LongRequestLogger/trunk/docs/HISTORY.txt
-=-
Modified: Products.LongRequestLogger/trunk/Products/LongRequestLogger/dumper.py
===================================================================
--- Products.LongRequestLogger/trunk/Products/LongRequestLogger/dumper.py 2012-01-31 10:36:24 UTC (rev 124265)
+++ Products.LongRequestLogger/trunk/Products/LongRequestLogger/dumper.py 2012-01-31 10:37:01 UTC (rev 124266)
@@ -1,24 +1,35 @@
##############################################################################
#
-# Copyright (c) 2010 Zope Foundation and Contributors.
+# Copyright (c) 2010,2012 Zope Foundation and Contributors.
#
##############################################################################
+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
import traceback
-import logging
-from cStringIO import StringIO
-from thread import get_ident
-import time
-from pprint import pformat
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
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 @@
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,22 +58,36 @@
# 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(
timeout=float(os.environ.get('longrequestlogger_timeout',
Modified: Products.LongRequestLogger/trunk/docs/HISTORY.txt
===================================================================
--- Products.LongRequestLogger/trunk/docs/HISTORY.txt 2012-01-31 10:36:24 UTC (rev 124265)
+++ Products.LongRequestLogger/trunk/docs/HISTORY.txt 2012-01-31 10:37:01 UTC (rev 124266)
@@ -1,7 +1,14 @@
Changelog
=========
-1.0
+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
More information about the checkins
mailing list