[Zodb-checkins] CVS: Zope/lib/python/zLOG - EventLogger.py:1.10 component.xml:1.11 datatypes.py:1.15 LogHandlers.py:NONE factory.py:NONE

Fred L. Drake, Jr. fred at zope.com
Mon Jan 5 12:04:43 EST 2004


Update of /cvs-repository/Zope/lib/python/zLOG
In directory cvs.zope.org:/tmp/cvs-serv2498/zLOG

Modified Files:
	EventLogger.py component.xml datatypes.py 
Removed Files:
	LogHandlers.py factory.py 
Log Message:
update zLOG configuration component to make use of the ZConfig support for
the logging package; this avoids lots of code duplication


=== Zope/lib/python/zLOG/EventLogger.py 1.9 => 1.10 ===
--- Zope/lib/python/zLOG/EventLogger.py:1.9	Sat Aug  2 01:34:32 2003
+++ Zope/lib/python/zLOG/EventLogger.py	Mon Jan  5 12:04:12 2004
@@ -22,7 +22,7 @@
 import os, sys, time
 import logging
 from BaseLogger import BaseLogger
-from LogHandlers import FileHandler, NullHandler, SysLogHandler
+from ZConfig.components.logger import loghandler
 from logging import StreamHandler, Formatter
 
 # Custom logging levels
@@ -36,7 +36,7 @@
     # Get our logger object:
     logger = logging.getLogger('event')
     # Add a null handler to prevent warnings about loggers with no handlers:
-    logger.addHandler(NullHandler())
+    logger.addHandler(loghandler.NullHandler())
     logger.propagate = 0
 
     def log(self, subsystem, severity, summary, detail, error):
@@ -174,14 +174,14 @@
     # set up syslog handler if necessary
     facility, syslogdest = get_env_syslog_info()
     if syslogdest:
-        handler = SysLogHandler(syslogdest, facility)
+        handler = loghandler.SysLogHandler(syslogdest, facility)
         handler.setFormatter(formatters['syslog'])
         handlers.append(handler)
 
     # set up file handler if necessary
     filedest = get_env_file_info()
     if filedest:
-        handler = FileHandler(filedest)
+        handler = loghandler.FileHandler(filedest)
         handler.setFormatter(formatters['file'])
         handlers.append(handler)
     elif filedest == '':
@@ -192,7 +192,7 @@
     else:
         # log to nowhere, but install a 'null' handler in order to
         # prevent error messages from emanating due to a missing handler
-        handlers.append(NullHandler())
+        handlers.append(loghandler.NullHandler())
 
     severity = get_env_severity_info()
     severity = zlog_to_pep282_severity(severity)


=== Zope/lib/python/zLOG/component.xml 1.10 => 1.11 ===
--- Zope/lib/python/zLOG/component.xml:1.10	Thu Nov  6 02:59:11 2003
+++ Zope/lib/python/zLOG/component.xml	Mon Jan  5 12:04:12 2004
@@ -1,61 +1,17 @@
 <component prefix="zLOG.datatypes">
 
-  <abstracttype name="zLOG.loghandler"/>
+  <import package="ZConfig.components.logger" file="abstract.xml"/>
+  <import package="ZConfig.components.logger" file="handlers.xml"/>
 
-  <sectiontype name="zLOG.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="notset" datatype=".logging_level"/>
-  </sectiontype>
-
-  <sectiontype name="logfile" datatype=".FileHandlerFactory"
-               implements="zLOG.loghandler" extends="zLOG.base-log-handler">
-    <key name="path" required="yes"/>
-    <key name="format" default="------\n%(asctime)s %(message)s"
-         datatype=".log_format"/>
-  </sectiontype>
-
-  <sectiontype name="syslog" datatype=".SyslogHandlerFactory"
-               implements="zLOG.loghandler" extends="zLOG.base-log-handler">
-    <key name="facility" default="user" datatype=".syslog_facility"/>
-    <key name="address" datatype="socket-address" default="localhost:514"/>
-    <key name="format" default="%(message)s"
-         datatype=".log_format"/>
-  </sectiontype>
-
-  <sectiontype name="win32-eventlog" datatype=".Win32EventLogFactory"
-               implements="zLOG.loghandler" extends="zLOG.base-log-handler">
-    <key name="appname" default="Zope"/>
-    <key name="format" default="%(message)s"
-         datatype=".log_format"/>
-  </sectiontype>
-
-  <sectiontype name="http-logger" datatype=".HTTPHandlerFactory"
-               implements="zLOG.loghandler" extends="zLOG.base-log-handler">
-    <key name="url" default="http://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"/>
-  </sectiontype>
-
-  <sectiontype name="email-notifier" datatype=".SMTPHandlerFactory"
-               implements="zLOG.loghandler" extends="zLOG.base-log-handler">
-    <key name="from" required="yes" attribute="fromaddr"/>
-    <multikey name="to" required="yes" attribute="toaddrs"/>
-    <key name="subject" default="Message from Zope"/>
-    <key name="smtp-server" default="localhost" datatype="inet-address"/>
-    <key name="format" default="%(asctime)s %(message)s"
-         datatype=".log_format"/>
-  </sectiontype>
-
-
-  <sectiontype name="eventlog" datatype=".EventLogFactory">
-     <key name="level" datatype=".logging_level" default="info"/>
-     <multisection type="zLOG.loghandler" attribute="handlers" name="*"/>
+  <sectiontype name="eventlog"
+               datatype=".EventLogFactory">
+     <key name="level"
+          datatype="ZConfig.components.logger.datatypes.logging_level"
+          default="info"/>
+     <multisection name="*"
+                   type="ZConfig.logger.handler"
+                   attribute="handlers"
+                   />
   </sectiontype>
 
 </component>


=== Zope/lib/python/zLOG/datatypes.py 1.14 => 1.15 ===
--- Zope/lib/python/zLOG/datatypes.py:1.14	Wed Dec 31 15:38:41 2003
+++ Zope/lib/python/zLOG/datatypes.py	Mon Jan  5 12:04:12 2004
@@ -14,191 +14,10 @@
 
 """ZConfig datatypes for logging support."""
 
-import sys
-
 import zLOG
 
 from zLOG import EventLogger
-from zLOG.factory import Factory
-
-# log-related datatypes
-
-_logging_levels = {
-    "critical": 50,
-    "fatal": 50,
-    "error": 40,
-    "warn": 30,
-    "warning": 30,
-    "info": 20,
-    "blather": 15,
-    "debug": 10,
-    "trace": 5,
-    "all": 1,
-    "notset": 0,
-    }
-
-def logging_level(value):
-    s = str(value).lower()
-    if _logging_levels.has_key(s):
-        return _logging_levels[s]
-    else:
-        v = int(s)
-        if v < 0 or v > 50:
-            raise ValueError("log level not in range: " + `v`)
-        return v
-
-_log_format_variables = {
-    'name': '',
-    'levelno': '3',
-    'levelname': 'DEBUG',
-    'pathname': 'apath',
-    'filename': 'afile',
-    'module': 'amodule',
-    'lineno': 1,
-    'created': 1.1,
-    'asctime': 'atime',
-    'msecs': 1,
-    'relativeCreated': 1,
-    'thread': 1,
-    'message': 'amessage',
-    }
-
-def log_format(value):
-    value = ctrl_char_insert(value)
-    try:
-        # Make sure the format string uses only names that will be
-        # provided, and has reasonable type flags for each, and does
-        # not expect positional args.
-        value % _log_format_variables
-    except (ValueError, KeyError):
-        raise ValueError, 'Invalid log format string %s' % value
-    return value
-
-_control_char_rewrites = {r'\n': '\n', r'\t': '\t', r'\b': '\b',
-                          r'\f': '\f', r'\r': '\r'}.items()
-
-def ctrl_char_insert(value):
-    for pattern, replacement in _control_char_rewrites:
-        value = value.replace(pattern, replacement)
-    return value
-
-
-class HandlerFactory(Factory):
-    def __init__(self, section):
-        Factory.__init__(self)
-        self.section = section
-
-    def create_loghandler(self):
-        raise NotImplementedError(
-            "subclasses must override create_loghandler()")
-
-    def create(self):
-        import logging
-        logger = self.create_loghandler()
-        logger.setFormatter(logging.Formatter(self.section.format,
-                                              self.section.dateformat))
-        logger.setLevel(self.section.level)
-        return logger
-
-    def getLevel(self):
-        return self.section.level
-
-class FileHandlerFactory(HandlerFactory):
-    def create_loghandler(self):
-        from zLOG.LogHandlers import StreamHandler, FileHandler
-        path = self.section.path
-        if path == "STDERR":
-            return StreamHandler(sys.stderr)
-        if path == "STDOUT":
-            return StreamHandler(sys.stdout)
-        return FileHandler(path)
-
-_syslog_facilities = {
-    "auth": 1,
-    "authpriv": 1,
-    "cron": 1,
-    "daemon": 1,
-    "kern": 1,
-    "lpr": 1,
-    "mail": 1,
-    "news": 1,
-    "security": 1,
-    "syslog": 1,
-    "user": 1,
-    "uucp": 1,
-    "local0": 1,
-    "local1": 1,
-    "local2": 1,
-    "local3": 1,
-    "local4": 1,
-    "local5": 1,
-    "local6": 1,
-    "local7": 1,
-    }
-
-def syslog_facility(value):
-    value = value.lower()
-    if not _syslog_facilities.has_key(value):
-        L = _syslog_facilities.keys()
-        L.sort()
-        raise ValueError("Syslog facility must be one of " + ", ".join(L))
-    return value
-
-class SyslogHandlerFactory(HandlerFactory):
-    def create_loghandler(self):
-        from zLOG.LogHandlers import SysLogHandler
-        return SysLogHandler(self.section.address.address,
-                             self.section.facility)
-
-class Win32EventLogFactory(HandlerFactory):
-    def create_loghandler(self):
-        from zLOG.LogHandlers import Win32EventLogHandler
-        return Win32EventLogHandler(self.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
-
-class HTTPHandlerFactory(HandlerFactory):
-    def create_loghandler(self):
-        from zLOG.LogHandlers import HTTPHandler
-        host, selector = self.section.url
-        return HTTPHandler(host, selector, self.section.method)
-
-class SMTPHandlerFactory(HandlerFactory):
-    def create_loghandler(self):
-        from zLOG.LogHandlers import SMTPHandler
-        host, port = self.section.smtp_server
-        if not port:
-            mailhost = host
-        else:
-            mailhost = host, port
-        return SMTPHandler(mailhost, self.section.fromaddr,
-                           self.section.toaddrs, self.section.subject)
+from ZConfig.components.logger.factory import Factory
 
 
 class EventLogFactory(Factory):
@@ -227,7 +46,7 @@
                 handler = handler_factory()
                 logger.addHandler(handler)
         else:
-            from zLOG.LogHandlers import NullHandler
+            from ZConfig.components.logger.loghandler import NullHandler
             logger.addHandler(NullHandler())
         return logger
 
@@ -252,23 +71,3 @@
     def startup(self):
         zLOG.set_initializer(self.initialize)
         zLOG.initialize()
-
-
-def importable_name(name):
-    try:
-        components = name.split('.')
-        start = components[0]
-        g = globals()
-        package = __import__(start, g, g)
-        modulenames = [start]
-        for component in components[1:]:
-            modulenames.append(component)
-            try:
-                package = getattr(package, component)
-            except AttributeError:
-                n = '.'.join(modulenames)
-                package = __import__(n, g, g, component)
-        return package
-    except ImportError:
-        raise ValueError, (
-            'The object named by "%s" could not be imported' %  name )

=== Removed File Zope/lib/python/zLOG/LogHandlers.py ===

=== Removed File Zope/lib/python/zLOG/factory.py ===




More information about the Zodb-checkins mailing list