[Zodb-checkins] CVS: ZODB3/zLOG - component.xml:1.3 datatypes.py:1.4

Fred L. Drake, Jr. fred@zope.com
Mon, 20 Jan 2003 18:25:43 -0500


Update of /cvs-repository/ZODB3/zLOG
In directory cvs.zope.org:/tmp/cvs-serv21226/zLOG

Modified Files:
	component.xml datatypes.py 
Log Message:
- re-enable several loghandler types
- make it easier for an admin to configure logging levels
  (by making the defaults more sane)
- refactor the tests a little, in preparation for more tests


=== ZODB3/zLOG/component.xml 1.2 => 1.3 ===
--- ZODB3/zLOG/component.xml:1.2	Thu Jan 16 10:35:57 2003
+++ ZODB3/zLOG/component.xml	Mon Jan 20 18:25:09 2003
@@ -2,60 +2,57 @@
 
   <abstracttype name="loghandler"/>
 
-  <sectiontype name="file-handler" datatype=".file_handler"
-               implements="loghandler">
+  <sectiontype name="base-log-handler">
+    <description>
+      Base type for most log handlers.  This is cannot be used as a
+      loghandler directly since it doesn't implement the loghandler
+      abstract section type.
+    </description>
+    <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
+    <key name="level" default="info" datatype=".logging_level"/>
+  </sectiontype>
+
+  <sectiontype name="logfile" datatype=".file_handler"
+               implements="loghandler" extends="base-log-handler">
     <key name="path" required="yes"/>
     <key name="format" default="------\n%(asctime)s %(message)s"
          datatype=".log_format"/>
-    <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
-  <sectiontype name="syslog-handler" datatype=".syslog_handler"
-               implements="loghandler">
+  <sectiontype name="syslog" datatype=".syslog_handler"
+               implements="loghandler" extends="base-log-handler">
     <key name="facility" default="user" datatype=".syslog_facility"/>
     <key name="address" datatype="socket-address" required="yes"/>
     <key name="format" default="%(message)s"
          datatype=".log_format"/>
-    <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
-<!--
-  <sectiontype name="nteventlog_handler" datatype=".nteventlog_handler"
-               implements="loghandler">
+  <sectiontype name="nteventlog" datatype=".nteventlog_handler"
+               implements="loghandler" extends="base-log-handler">
     <key name="appname" default="Zope"/>
     <key name="format" default="%(message)s"
          datatype=".log_format"/>
-    <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
   <sectiontype name="http_handler" datatype=".http_handler"
-               implements="loghandler">
+               implements="loghandler" extends="base-log-handler">
     <key name="url" default="localhost" datatype=".http_handler_url"/>
     <key name="method" default="GET" datatype=".get_or_post"/>
     <key name="format" default="%(asctime)s %(message)s"
          datatype=".log_format"/>
-    <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
   <sectiontype name="smtp_handler" datatype=".smtp_handler"
-               implements="loghandler">
+               implements="loghandler" extends="base-log-handler">
     <key name="fromaddr" required="yes"/>
     <multikey name="toaddr" required="yes" attribute="toaddrs"/>
     <key name="subject" default="Message from Zope"/>
     <key name="host" default="localhost" datatype="inet-address"/>
     <key name="format" default="%(asctime)s %(message)s"
          datatype=".log_format"/>
-    <key name="dateformat" default="%Y-%m-%dT%H:%M:%S"/>
-    <key name="level" default="info" datatype=".logging_level"/>
   </sectiontype>
 
-  <sectiontype name="null_handler" datatype=".null_handler"
-               implements="loghandler"/>
-
+<!--
   <sectiontype name="custom_handler" datatype=".custom_handler"
                implements="loghandler">
     <key name="constructor" datatype="constructor" required="yes"/>
@@ -66,7 +63,7 @@
 -->
 
   <sectiontype name="logger" datatype=".logger">
-     <key name="level" datatype=".logging_level" default="info"/>
+     <key name="level" datatype=".logging_level" default="all"/>
      <multisection type="loghandler" attribute="handlers" name="*"/>
   </sectiontype>
 


=== ZODB3/zLOG/datatypes.py 1.3 => 1.4 ===
--- ZODB3/zLOG/datatypes.py:1.3	Thu Jan 16 10:35:57 2003
+++ ZODB3/zLOG/datatypes.py	Mon Jan 20 18:25:09 2003
@@ -136,84 +136,80 @@
                    section.address.address,
                    section.facility)
 
-## def nteventlog_handler(section):
-##     appname = section.appname
-##     format = section.format
-##     dateformat = section.dateformat
-##     level = section.level
-    
-##     formatter = Factory('logging.Formatter', None, format, dateformat)
-
-##     def callback(inst, formatter=formatter, level=level):
-##         inst.setFormatter(formatter())
-##         inst.setLevel(level)
-
-##     return Factory('zLOG.LogHandlers.NTEventLogHandler', callback, appname)
-
-## def http_handler_url(value):
-##     import urlparse
-##     scheme, netloc, path, query, fragment = urlparse.urlsplit(value)
-##     if scheme != 'http':
-##         raise ValueError, 'url must be an http url'
-##     if not netloc:
-##         raise ValueError, 'url must specify a location'
-##     if not path:
-##         raise ValueError, 'url must specify a path'
-##     q = []
-##     if query:
-##         q.append('?')
-##         q.append(query)
-##     if fragment:
-##         q.append('#')
-##         q.append(fragment)
-##     return (netloc, path + ''.join(q))
-
-## def get_or_post(value):
-##     value = value.upper()
-##     if value not in ('GET', 'POST'):
-##         raise ValueError, ('method must be "GET" or "POST", instead received '
-##                            '%s' % repr(value))
-##     return value
-
-## def http_handler(section):
-##     host, url = section.url
-##     method     = section.method
-##     format     = section.format
-##     dateformat = section.dateformat
-##     level      = section.level
-    
-##     formatter = Factory('logging.Formatter', None, format, dateformat)
-
-##     def callback(inst, formatter=formatter, level=level):
-##         inst.setFormatter(formatter())
-##         inst.setLevel(level)
-
-##     return Factory('zLOG.LogHandlers.HTTPHandler', callback, host, url, method)
-
-## def smtp_handler(section):
-##     fromaddr   = section.fromaddr
-##     toaddrs    = section.toaddrs
-##     subject    = section.subject
-##     host, port = section.host
-##     format     = section.format
-##     dateformat = section.dateformat
-##     level      = section.level
-    
-##     if not port:
-##         mailhost = host
-##     else:
-##         mailhost = host, port
-##     formatter = Factory('logging.Formatter', None, format, dateformat)
-
-##     def callback(inst, formatter=formatter, level=level):
-##         inst.setFormatter(formatter())
-##         inst.setLevel(level)
-
-##     return Factory('zLOG.LogHandlers.SMTPHandler', callback,
-##                    mailhost, fromaddr, toaddrs, subject)
-
-## def null_handler(section):
-##     return Factory('zLOG.LogHandlers.NullHandler', None)
+def nteventlog_handler(section):
+    def callback(inst,
+                 format=section.format,
+                 dateformat=section.dateformat,
+                 level=section.level):
+        import logging
+        inst.setFormatter(logging.Formatter(format, dateformat))
+        inst.setLevel(level)
+
+    return Factory('zLOG.LogHandlers.NTEventLogHandler', callback,
+                   section.appname)
+
+def http_handler_url(value):
+    import urlparse
+    scheme, netloc, path, param, query, fragment = urlparse.urlparse(value)
+    if scheme != 'http':
+        raise ValueError, 'url must be an http url'
+    if not netloc:
+        raise ValueError, 'url must specify a location'
+    if not path:
+        raise ValueError, 'url must specify a path'
+    q = []
+    if param:
+        q.append(';')
+        q.append(param)
+    if query:
+        q.append('?')
+        q.append(query)
+    if fragment:
+        q.append('#')
+        q.append(fragment)
+    return (netloc, path + ''.join(q))
+
+def get_or_post(value):
+    value = value.upper()
+    if value not in ('GET', 'POST'):
+        raise ValueError('method must be "GET" or "POST", instead received: '
+                         + repr(value))
+    return value
+
+def http_handler(section):
+    def callback(inst,
+                 format=section.format,
+                 dateformat=section.dateformat,
+                 level=section.level):
+        import logging
+        inst.setFormatter(logging.Formatter(format, dateformat))
+        inst.setLevel(level)
+
+    host, selector = section.url
+    return Factory('zLOG.LogHandlers.HTTPHandler',
+                   callback, host, selector, section.method)
+
+def smtp_handler(section):
+    def callback(inst,
+                 format=section.format,
+                 dateformat=section.dateformat,
+                 level=section.level):
+        import logging
+        inst.setFormatter(logging.Formatter(format, dateformat))
+        inst.setLevel(level)
+
+    host, port = section.host
+    if not port:
+        mailhost = host
+    else:
+        mailhost = host, port
+
+    return Factory('zLOG.LogHandlers.SMTPHandler',
+                   callback,
+                   mailhost,
+                   section.fromaddr,
+                   section.toaddrs,
+                   section.subject)
 
 ## def custom_handler(section):
 ##     formatter_klass, formatter_pos, formatter_kw = section.formatter
@@ -257,7 +253,7 @@
             logger.setLevel(self.level)
             if self.handler_factories:
                 for handler_factory in self.handler_factories:
-                    handler =  handler_factory()
+                    handler = handler_factory()
                     logger.addHandler(handler)
             else:
                 from zLOG.LogHandlers import NullHandler