summaryrefslogtreecommitdiff
path: root/Mailman/loginit.py
diff options
context:
space:
mode:
authormsapiro2006-10-24 03:55:24 +0000
committermsapiro2006-10-24 03:55:24 +0000
commit3256c431e7bf966d3de49e4dc31dd01d57ffb02f (patch)
treee0f32257c2bc73eec34e4ebf2f50c27b0ff23a66 /Mailman/loginit.py
parentf0a263b63991efc787bfd870bd7a491c53dce54a (diff)
downloadmailman-3256c431e7bf966d3de49e4dc31dd01d57ffb02f.tar.gz
mailman-3256c431e7bf966d3de49e4dc31dd01d57ffb02f.tar.zst
mailman-3256c431e7bf966d3de49e4dc31dd01d57ffb02f.zip
Updated the mmshell scripts so all use the configuration.py config object
instead of mm_cfg.py. This involved mostly mechanical replacements, but there were a few gotchas to make sure that various calls and assignments that ultimately referenced the config were delayed until after the config was loaded. Updated configuration.py to throw an exception if config.load() is called with a non-existent filename argument. Updated loginit.py to add the fromusenet log used by gate_news.py.
Diffstat (limited to 'Mailman/loginit.py')
-rw-r--r--Mailman/loginit.py262
1 files changed, 132 insertions, 130 deletions
diff --git a/Mailman/loginit.py b/Mailman/loginit.py
index 2dfa00837..85762e7ec 100644
--- a/Mailman/loginit.py
+++ b/Mailman/loginit.py
@@ -1,130 +1,132 @@
-# Copyright (C) 2006 by the Free Software Foundation, Inc.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-
-"""Logging initialization, using Python's standard logging package.
-
-This module cannot be called 'logging' because that would interfere with the
-import below. Ah, for Python 2.5 and absolute imports.
-"""
-
-import os
-import codecs
-import logging
-
-from Mailman.configuration import config
-
-FMT = '%(asctime)s (%(process)d) %(message)s'
-DATEFMT = '%b %d %H:%M:%S %Y'
-LOGGERS = (
- 'bounce',
- 'config',
- 'debug',
- 'error',
- 'http',
- 'locks',
- 'mischief',
- 'post',
- 'qrunner',
- 'smtp',
- 'smtp-failure',
- 'subscribe',
- 'vette',
- )
-
-_handlers = []
-
-
-
-class ReopenableFileHandler(logging.Handler):
- def __init__(self, filename):
- self._filename = filename
- self._stream = self._open()
- logging.Handler.__init__(self)
-
- def _open(self):
- return codecs.open(self._filename, 'a', 'utf-8')
-
- def flush(self):
- self._stream.flush()
-
- def emit(self, record):
- try:
- msg = self.format(record)
- fs = '%s\n'
- try:
- self._stream.write(fs % msg)
- except UnicodeError:
- self._stream.write(fs % msg.encode('string-escape'))
- self.flush()
- except:
- self.handleError(record)
-
- def close(self):
- self.flush()
- self._stream.close()
- logging.Handler.close(self)
-
- def reopen(self):
- self._stream.close()
- self._stream = self._open()
-
-
-
-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:
- #
- # 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
- #
- # There was also a 'debug' logger, but that was mostly unused, so instead
- # we'll use debug level on existing loggers.
- #
- # 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)
- # Create the subloggers
- for logger in LOGGERS:
- log = logging.getLogger('mailman.' + logger)
- # 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))
- _handlers.append(handler)
- handler.setFormatter(formatter)
- log.addHandler(handler)
-
-
-
-def reopen():
- for handler in _handlers:
- handler.reopen()
+# Copyright (C) 2006 by the Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+"""Logging initialization, using Python's standard logging package.
+
+This module cannot be called 'logging' because that would interfere with the
+import below. Ah, for Python 2.5 and absolute imports.
+"""
+
+import os
+import codecs
+import logging
+
+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',
+ )
+
+_handlers = []
+
+
+
+class ReopenableFileHandler(logging.Handler):
+ def __init__(self, filename):
+ self._filename = filename
+ self._stream = self._open()
+ logging.Handler.__init__(self)
+
+ def _open(self):
+ return codecs.open(self._filename, 'a', 'utf-8')
+
+ def flush(self):
+ self._stream.flush()
+
+ def emit(self, record):
+ try:
+ msg = self.format(record)
+ fs = '%s\n'
+ try:
+ self._stream.write(fs % msg)
+ except UnicodeError:
+ self._stream.write(fs % msg.encode('string-escape'))
+ self.flush()
+ except:
+ self.handleError(record)
+
+ def close(self):
+ self.flush()
+ self._stream.close()
+ logging.Handler.close(self)
+
+ def reopen(self):
+ self._stream.close()
+ self._stream = self._open()
+
+
+
+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:
+ #
+ # 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
+ #
+ # There was also a 'debug' logger, but that was mostly unused, so instead
+ # we'll use debug level on existing loggers.
+ #
+ # 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)
+ # Create the subloggers
+ for logger in LOGGERS:
+ log = logging.getLogger('mailman.' + logger)
+ # 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))
+ _handlers.append(handler)
+ handler.setFormatter(formatter)
+ log.addHandler(handler)
+
+
+
+def reopen():
+ for handler in _handlers:
+ handler.reopen()