[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/StartUp - SiteDefinition.py:1.12 meta.zcml:1.3

Guido van Rossum guido@python.org
Thu, 19 Dec 2002 21:39:30 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/StartUp
In directory cvs.zope.org:/tmp/cvs-serv11858/lib/python/Zope/App/StartUp

Modified Files:
	SiteDefinition.py meta.zcml 
Log Message:
Add support for setting the logging level via the useLog directive.


=== Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py 1.11 => 1.12 ===
--- Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py:1.11	Thu Dec 19 20:56:39 2002
+++ Zope3/lib/python/Zope/App/StartUp/SiteDefinition.py	Thu Dec 19 21:39:30 2002
@@ -40,7 +40,7 @@
 
 DEFAULT_STORAGE_FILE = 'Data.fs'
 DEFAULT_LOG_FILE = 'STDERR'
-DEFAULT_LOG_CLASS = 'Zope.Server.HTTPServer.CommonHitLogger'
+DEFAULT_LOG_LEVEL = 'INFO'
 
 
 class SiteDefinition:
@@ -52,6 +52,16 @@
     _special_log_files = {'STDERR': sys.stderr,
                           'STDOUT': sys.stdout}
 
+    # Mapping from log level names to numeric log levels
+    _log_levels = {
+        'CRITICAL' : logging.CRITICAL,
+        'ERROR' : logging.ERROR,
+        'WARN' : logging.WARN,
+        'INFO' : logging.INFO,
+        'DEBUG' : logging.DEBUG,
+        'NOTSET' : logging.NOTSET,
+        }
+
     
     def __init__(self, _context, name="default", threads=4):
         """Initialize is called when defineSite directive is invoked."""
@@ -79,11 +89,17 @@
         return []
 
 
-    def useLog(self, _context, file=DEFAULT_LOG_FILE):
-        """Lets you specify the log file to use"""
+    def useLog(self, _context, file=DEFAULT_LOG_FILE, level=DEFAULT_LOG_LEVEL):
+        """Lets you specify the log file and level to use"""
+
+        # Translate the level to logging
+        loglevel = self._log_levels.get(level.upper())
+        if loglevel is None:
+            raise ValueError, "unknown log level %r" % level
 
-        # Get the root logger
+        # Get the root logger and set its logging level
         root = logging.root
+        root.setLevel(loglevel)
 
         # Remove previous handlers
         for h in root.handlers[:]:


=== Zope3/lib/python/Zope/App/StartUp/meta.zcml 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/StartUp/meta.zcml:1.2	Tue Nov 19 18:25:14 2002
+++ Zope3/lib/python/Zope/App/StartUp/meta.zcml	Thu Dec 19 21:39:30 2002
@@ -11,7 +11,7 @@
 
       <subdirective name="useMappingStorage" />
 
-      <subdirective name="useLog" attributes="file" />
+      <subdirective name="useLog" attributes="file level" />
 
       <subdirective name="addServer"
                     attributes="type port verbose logClass" />