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.
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
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)
107
126
def initialize(propagate=None):
108
127
"""Initialize all logs.
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')
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)
159
_init_logger(propagate, sub_name, log, logger_config)