~abompard/mailman/bug-1312884

« back to all changes in this revision

Viewing changes to src/mailman/core/logging.py

  • Committer: Barry Warsaw
  • Date: 2014-11-01 16:49:15 UTC
  • mfrom: (7251.1.38 abhilash)
  • Revision ID: barry@list.org-20141101164915-06wqfmya6wf47n6n
Database
--------
 * The ORM layer, previously implemented with Storm, has been replaced by
   SQLAlchemy, thanks to the fantastic work by Abhilash Raj and Aurélien
   Bompard.  Alembic is now used for all database schema migrations.
 * The new logger `mailman.database` logs any errors at the database layer.

API
---
 * Several changes to the internal API:
   - `IListManager.mailing_lists` is guaranteed to be sorted in List-ID order.
   - `IDomains.mailing_lists` is guaranteed to be sorted in List-ID order.
   - Iteration over domains via the `IDomainManager` is guaranteed to be sorted
     by `IDomain.mail_host` order.
   - `ITemporaryDatabase` interface and all implementations are removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
import logging
33
33
 
34
34
from lazr.config import as_boolean, as_log_level
35
 
 
36
35
from mailman.config import config
37
36
 
38
37
 
42
41
 
43
42
# XXX I would love to simplify things and use Python's WatchedFileHandler, but
44
43
# there are two problems.  First, it's more difficult to handle the test
45
 
# suite's need to reopen the file handler to a different path.  Does
46
 
# zope.testing's logger support fix this?
 
44
# suite's need to reopen the file handler to a different path.
47
45
#
48
46
# The other problem is that WatchedFileHandler doesn't really easily support
49
47
# HUPing the process to reopen the log file.  Now, maybe that's not a big deal
104
102
 
105
103
 
106
104
 
 
105
def _init_logger(propagate, sub_name, log, logger_config):
 
106
    # Get settings from log configuration file (or defaults).
 
107
    log_format = logger_config.format
 
108
    log_datefmt = logger_config.datefmt
 
109
    # Propagation to the root logger is how we handle logging to stderr
 
110
    # when the runners are not run as a subprocess of 'bin/mailman start'.
 
111
    log.propagate = (as_boolean(logger_config.propagate)
 
112
                     if propagate is None else propagate)
 
113
    # Set the logger's level.
 
114
    log.setLevel(as_log_level(logger_config.level))
 
115
    # Create a formatter for this logger, then a handler, and link the
 
116
    # formatter to the handler.
 
117
    formatter = logging.Formatter(fmt=log_format, datefmt=log_datefmt)
 
118
    path_str = logger_config.path
 
119
    path_abs = os.path.normpath(os.path.join(config.LOG_DIR, path_str))
 
120
    handler = ReopenableFileHandler(sub_name, path_abs)
 
121
    _handlers[sub_name] = handler
 
122
    handler.setFormatter(formatter)
 
123
    log.addHandler(handler)
 
124
 
 
125
 
107
126
def initialize(propagate=None):
108
127
    """Initialize all logs.
109
128
 
126
145
            continue
127
146
        if sub_name == 'locks':
128
147
            log = logging.getLogger('flufl.lock')
 
148
        if sub_name == 'database':
 
149
            # Set both the SQLAlchemy and Alembic logs to the mailman.database
 
150
            # log configuration, essentially ignoring the alembic.cfg settings.
 
151
            # Do the SQLAlchemy one first, then let the Alembic one fall
 
152
            # through to the common code path.
 
153
            log = logging.getLogger('sqlalchemy')
 
154
            _init_logger(propagate, sub_name, log, logger_config)
 
155
            log = logging.getLogger('alembic')
129
156
        else:
130
157
            logger_name = 'mailman.' + sub_name
131
158
            log = logging.getLogger(logger_name)
132
 
        # Get settings from log configuration file (or defaults).
133
 
        log_format = logger_config.format
134
 
        log_datefmt = logger_config.datefmt
135
 
        # Propagation to the root logger is how we handle logging to stderr
136
 
        # when the runners are not run as a subprocess of 'bin/mailman start'.
137
 
        log.propagate = (as_boolean(logger_config.propagate)
138
 
                         if propagate is None else propagate)
139
 
        # Set the logger's level.
140
 
        log.setLevel(as_log_level(logger_config.level))
141
 
        # Create a formatter for this logger, then a handler, and link the
142
 
        # formatter to the handler.
143
 
        formatter = logging.Formatter(fmt=log_format, datefmt=log_datefmt)
144
 
        path_str = logger_config.path
145
 
        path_abs = os.path.normpath(os.path.join(config.LOG_DIR, path_str))
146
 
        handler = ReopenableFileHandler(sub_name, path_abs)
147
 
        _handlers[sub_name] = handler
148
 
        handler.setFormatter(formatter)
149
 
        log.addHandler(handler)
150
 
 
 
159
        _init_logger(propagate, sub_name, log, logger_config)
151
160
 
152
161
 
153
162
def reopen():