summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/commands/docs/conf.rst1
-rw-r--r--src/mailman/config/schema.cfg3
-rw-r--r--src/mailman/core/logging.py49
3 files changed, 34 insertions, 19 deletions
diff --git a/src/mailman/commands/docs/conf.rst b/src/mailman/commands/docs/conf.rst
index 7b8529ac3..2f708edc5 100644
--- a/src/mailman/commands/docs/conf.rst
+++ b/src/mailman/commands/docs/conf.rst
@@ -49,6 +49,7 @@ key, along with the names of the corresponding sections.
[logging.config] path: mailman.log
[logging.error] path: mailman.log
[logging.smtp] path: smtp.log
+ [logging.database] path: mailman.log
[logging.http] path: mailman.log
[logging.root] path: mailman.log
[logging.fromusenet] path: mailman.log
diff --git a/src/mailman/config/schema.cfg b/src/mailman/config/schema.cfg
index e8f89ab41..ac09c1b07 100644
--- a/src/mailman/config/schema.cfg
+++ b/src/mailman/config/schema.cfg
@@ -231,6 +231,7 @@ alembic_scripts: mailman.database:alembic
# - archiver -- All archiver output
# - bounce -- All bounce processing logs go here
# - config -- Configuration issues
+# - database -- Database logging (SQLAlchemy and Alembic)
# - debug -- Only used for development
# - error -- All exceptions go to this log
# - fromusenet -- Information related to the Usenet to Mailman gateway
@@ -257,6 +258,8 @@ path: bounce.log
[logging.config]
+[logging.database]
+
[logging.debug]
path: debug.log
level: info
diff --git a/src/mailman/core/logging.py b/src/mailman/core/logging.py
index 43030436a..f4b9a1da1 100644
--- a/src/mailman/core/logging.py
+++ b/src/mailman/core/logging.py
@@ -104,6 +104,27 @@ class ReopenableFileHandler(logging.Handler):
+def _init_logger(propagate, sub_name, log, logger_config):
+ # Get settings from log configuration file (or defaults).
+ log_format = logger_config.format
+ log_datefmt = logger_config.datefmt
+ # Propagation to the root logger is how we handle logging to stderr
+ # when the runners are not run as a subprocess of 'bin/mailman start'.
+ log.propagate = (as_boolean(logger_config.propagate)
+ if propagate is None else propagate)
+ # Set the logger's level.
+ log.setLevel(as_log_level(logger_config.level))
+ # 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 = logger_config.path
+ path_abs = os.path.normpath(os.path.join(config.LOG_DIR, path_str))
+ handler = ReopenableFileHandler(sub_name, path_abs)
+ _handlers[sub_name] = handler
+ handler.setFormatter(formatter)
+ log.addHandler(handler)
+
+
def initialize(propagate=None):
"""Initialize all logs.
@@ -126,28 +147,18 @@ def initialize(propagate=None):
continue
if sub_name == 'locks':
log = logging.getLogger('flufl.lock')
+ if sub_name == 'database':
+ # Set both the SQLAlchemy and Alembic logs to the mailman.database
+ # log configuration, essentially ignoring the alembic.cfg
+ # settings. Do the SQLAlchemy one first, then let the Alembic one
+ # fall through to the common code path.
+ log = logging.getLogger('sqlalchemy')
+ _init_logger(propagate, sub_name, log, logger_config)
+ log = logging.getLogger('alembic')
else:
logger_name = 'mailman.' + sub_name
log = logging.getLogger(logger_name)
- # Get settings from log configuration file (or defaults).
- log_format = logger_config.format
- log_datefmt = logger_config.datefmt
- # Propagation to the root logger is how we handle logging to stderr
- # when the runners are not run as a subprocess of 'bin/mailman start'.
- log.propagate = (as_boolean(logger_config.propagate)
- if propagate is None else propagate)
- # Set the logger's level.
- log.setLevel(as_log_level(logger_config.level))
- # 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 = logger_config.path
- path_abs = os.path.normpath(os.path.join(config.LOG_DIR, path_str))
- handler = ReopenableFileHandler(sub_name, path_abs)
- _handlers[sub_name] = handler
- handler.setFormatter(formatter)
- log.addHandler(handler)
-
+ _init_logger(propagate, sub_name, log, logger_config)
def reopen():