[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/StartUp - SiteDefinition.py:1.11
Guido van Rossum
guido@python.org
Thu, 19 Dec 2002 20:56:41 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/StartUp
In directory cvs.zope.org:/tmp/cvs-serv6644
Modified Files:
SiteDefinition.py
Log Message:
Fix useLog(): remove previous handlers (otherwise we'd see duplicate
logging), and set a formatter that is compatible with the zLOG format.
=== Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py 1.10 => 1.11 ===
--- Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py:1.10 Thu Dec 19 18:05:22 2002
+++ Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py Thu Dec 19 20:56:39 2002
@@ -82,12 +82,31 @@
def useLog(self, _context, file=DEFAULT_LOG_FILE):
"""Lets you specify the log file to use"""
+ # Get the root logger
+ root = logging.root
+
+ # Remove previous handlers
+ for h in root.handlers[:]:
+ root.removeHandler(h)
+
+ # Create the new handler
if file in self._special_log_files.keys():
file = self._special_log_files[file]
handler = logging.StreamHandler(file)
else:
handler = logging.FileHandler(file)
- logging.root.addHandler(handler)
+
+ # Create a standard Zope-style formatter and set it
+ formatter = logging.Formatter(
+ "------\n"
+ "%(asctime)s %(levelname)s %(name)s %(message)s",
+ datefmt="%Y-%m-%dT%H:%M:%S")
+ handler.setFormatter(formatter)
+
+ # Set the handler
+ root.addHandler(handler)
+
+ # Return empty sequence to satisfy API
return []