[Zope3-checkins] CVS: Zope3/lib/python/Zope/Event - Logger.py:1.6

Guido van Rossum guido@python.org
Fri, 20 Dec 2002 10:58:51 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Event
In directory cvs.zope.org:/tmp/cvs-serv15770

Added Files:
	Logger.py 
Log Message:
Restore SteveA's Zope.Event.Logger module, converted to the logging package.

=== Zope3/lib/python/Zope/Event/Logger.py 1.5 => 1.6 ===
--- /dev/null	Fri Dec 20 10:58:51 2002
+++ Zope3/lib/python/Zope/Event/Logger.py	Fri Dec 20 10:58:20 2002
@@ -0,0 +1,50 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Helper class to log all events sent out by an event service.
+
+$Id$
+"""
+
+import logging
+import pprint
+from StringIO import StringIO
+
+from ISubscriber import ISubscriber
+
+class Logger:
+
+    """Helper class to log all events sent out by an event service.
+
+    This is an event subscriber that you can add via ZCML to log all
+    events sent out by Zope.
+    """
+
+    __implements__ = ISubscriber
+
+    def __init__(self, severity=logging.INFO):
+        self.severity = severity
+        self.logger = logging.getLogger("Event.Logger")
+
+    def notify(self, event):
+        c = event.__class__
+        detail = StringIO()
+        if 0:
+            # XXX Apparently this doesn't work; why not?
+            data = event.__dict__.items()
+            data.sort()
+            pprint(data, detail)
+        else:
+            print >>detail, 'XXX detail temporarily disabled'
+        self.logger.log(self.severity, "%s.%s: %s",
+                        c.__module__, c.__name__, detail.getvalue())