[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mailman-cvs
Subject:    [Mailman-checkins] SF.net SVN: mailman: [8185] trunk/mailman/Mailman
From:       bwarsaw () users ! sourceforge ! net
Date:       2007-03-31 23:56:58
Message-ID: E1HXnRK-0007jX-J0 () sc8-pr-svn1 ! sourceforge ! net
[Download RAW message or body]

Revision: 8185
          http://svn.sourceforge.net/mailman/?rev=8185&view=rev
Author:   bwarsaw
Date:     2007-03-31 16:56:58 -0700 (Sat, 31 Mar 2007)

Log Message:
-----------
Add a configuration variable called LOG_CONFIG_FILE.  If set, this names a
ConfigParser style ini file which can be used to override various default
settings for just the named loggers.

For example, if you want just the locks logger to print at DEBUG level, add
this:

etc/mailman.cfg:
LOG_CONFIG_FILE = 'etc/mailman.log'

etc/mailman.log:
[locks]
level = DEBUG

Modified Paths:
--------------
    trunk/mailman/Mailman/Defaults.py.in
    trunk/mailman/Mailman/loginit.py

Modified: trunk/mailman/Mailman/Defaults.py.in
===================================================================
--- trunk/mailman/Mailman/Defaults.py.in	2007-03-30 05:09:36 UTC (rev 8184)
+++ trunk/mailman/Mailman/Defaults.py.in	2007-03-31 23:56:58 UTC (rev 8185)
@@ -509,6 +509,24 @@
     ]
 
 
+# This defines a logging subsystem confirmation file, which overrides the
+# default log settings.  This is a ConfigParser formatted file which can
+# contain sections named after the logger name (without the leading 'mailman.'
+# common prefix).  Each section may contain the following options:
+#
+# - level     -- Overrides the default level; this may be any of the
+#                standard Python logging levels, case insensitive.
+# - format    -- Overrides the default format string; see below.
+# - datefmt   -- Overrides the default date format string; see below.
+# - path      -- Overrides the default logger path.  This may be a relative
+#                path name, in which case it is relative to Mailman's LOG_DIR,
+#                or it may be an absolute path name.  You cannot change the
+#                handler class that will be used.
+# - propagate -- Boolean specifying whether to propagate log message from this
+#                logger to the root "mailman" logger.  You cannot override
+#                settings for the root logger.
+LOG_CONFIG_FILE = None
+
 # This defines log format strings for the SMTPDirect delivery module (see
 # DELIVERY_MODULE above).  Valid %()s string substitutions include:
 #

Modified: trunk/mailman/Mailman/loginit.py
===================================================================
--- trunk/mailman/Mailman/loginit.py	2007-03-30 05:09:36 UTC (rev 8184)
+++ trunk/mailman/Mailman/loginit.py	2007-03-31 23:56:58 UTC (rev 8185)
@@ -24,32 +24,52 @@
 import os
 import codecs
 import logging
+import ConfigParser
 
 from Mailman.configuration import config
 
+
+
 FMT     = '%(asctime)s (%(process)d) %(message)s'
 DATEFMT = '%b %d %H:%M:%S %Y'
+
 LOGGERS = (
-    'bounce',
-    'config',
-    'debug',
-    'error',
-    'fromusenet',
-    'http',
-    'locks',
-    'mischief',
-    'post',
-    'qrunner',
-    'smtp',
-    'smtp-failure',
-    'subscribe',
-    'vette',
+    'bounce',       # All bounce processing logs go here
+    'config',       # Configuration issues
+    'debug',        # Only used for development
+    'error',        # All exceptions go to this log
+    'fromusenet',   # Information related to the Usenet to Mailman gateway
+    'http',         # Internal wsgi-based web interface
+    'locks',        # Lock state changes
+    'mischief',     # Various types of hostile activity
+    'post',         # Information about messages posted to mailing lists
+    'qrunner',      # qrunner start/stops
+    'smtp',         # Successful SMTP activity
+    'smtp-failure', # Unsuccessful SMTP activity
+    'subscribe',    # Information about leaves/joins
+    'vette',        # Information related to admindb activity
     )
 
 _handlers = []
 
 
 
+class ReallySafeConfigParser(ConfigParser.SafeConfigParser):
+    def getstring(self, section, option, default=None):
+        try:
+            return ConfigParser.SafeConfigParser.get(self, section, option)
+        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+            return default
+
+    def getboolean(self, section, option, default=None):
+        try:
+            return ConfigParser.SafeConfigParser.getboolean(
+                self, section, option)
+        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
+            return default
+
+
+
 class ReopenableFileHandler(logging.Handler):
     def __init__(self, filename):
         self._filename = filename
@@ -86,47 +106,41 @@
 
 
 def initialize(propagate=False):
-    # XXX Don't call logging.basicConfig() because in Python 2.3, it adds a
-    # handler to the root logger that we don't want.  When Python 2.4 is the
-    # minimum requirement, we can use basicConfig() with keyword arguments.
-    #
-    # The current set of Mailman logs are:
-    #
-    # debug         - Only used for development
-    # error         - All exceptions go to this log
-    # bounce        - All bounce processing logs go here
-    # mischief      - Various types of hostile activity
-    # post          - Information about messages posted to mailing lists
-    # vette         - Information related to admindb activity
-    # smtp          - Successful SMTP activity
-    # smtp-failure  - Unsuccessful SMTP activity
-    # subscribe     - Information about leaves/joins
-    # config        - Configuration issues
-    # locks         - Lock steals
-    # qrunner       - qrunner start/stops
-    # fromusenet    - Information related to the Usenet to Mailman gateway
-    #
-    # Start by creating a common formatter and the root logger.
-    formatter = logging.Formatter(fmt=FMT, datefmt=DATEFMT)
-    log = logging.getLogger('mailman')
-    handler = logging.StreamHandler()
-    handler.setFormatter(formatter)
-    log.addHandler(handler)
-    log.setLevel(logging.INFO)
+    # Initialize the root logger, then create a formatter for all the sublogs.
+    logging.basicConfig(format=FMT, datefmt=DATEFMT, level=logging.INFO)
+    # If a custom log configuration file was specified, load it now.  Note
+    # that we don't use logging.config.fileConfig() because it requires that
+    # all loggers, formatters, and handlers be defined.  We want to support
+    # minimal overloading of our logger configurations.
+    cp = ReallySafeConfigParser()
+    if config.LOG_CONFIG_FILE:
+        cp.read(config.LOG_CONFIG_FILE)
     # Create the subloggers
     for logger in LOGGERS:
         log = logging.getLogger('mailman.' + logger)
+        # Get settings from log configuration file (or defaults).
+        log_format      = cp.getstring(logger, 'format', FMT)
+        log_datefmt     = cp.getstring(logger, 'datefmt', DATEFMT)
         # Propagation to the root logger is how we handle logging to stderr
         # when the qrunners are not run as a subprocess of mailmanctl.
-        log.propagate = propagate
-        handler = ReopenableFileHandler(os.path.join(config.LOG_DIR, logger))
+        log.propagate   = cp.getboolean(logger, 'propagate', propagate)
+        # Set the logger's level.  Note that if the log configuration file
+        # does not set an override, the default level will be INFO except for
+        # the 'debug' logger.  It doesn't make much sense for the debug logger
+        # to ignore debug level messages!
+        level_str = cp.getstring(logger, 'level', 'INFO').upper()
+        level_def = (logging.DEBUG if logger == 'debug' else logging.INFO)
+        level_int = getattr(logging, level_str, level_def)
+        log.setLevel(level_int)
+        # Create a formatter for this logger, then a handler, and link the
+        # formatter to the handler.
+        formatter = logging.Formatter(fmt=log_format, datefmt=log_datefmt)
+        path_str  = cp.getstring(logger, 'path', logger)
+        path_abs  = os.path.normpath(os.path.join(config.LOG_DIR, path_str))
+        handler   = ReopenableFileHandler(path_abs)
         _handlers.append(handler)
         handler.setFormatter(formatter)
         log.addHandler(handler)
-        # It doesn't make much sense for the debug logger to ignore debug
-        # level messages.
-        if logger == 'debug':
-            log.setLevel(logging.DEBUG)
 
 
 


This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site. _______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/mailman-cvs%40progressive-comp.com



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic