summary refs log tree commit diff
path: root/synapse/config/logger.py
diff options
context:
space:
mode:
authorPaul Evans <leonerd@leonerd.org.uk>2015-09-15 10:47:40 +0100
committerPaul Evans <leonerd@leonerd.org.uk>2015-09-15 10:47:40 +0100
commit929ae19d009d973a9c4947967d117b678f65068d (patch)
tree4649bb6d7dffb1d6ae818f81e330162d7e864c13 /synapse/config/logger.py
parentMerge pull request #256 from matrix-org/auth (diff)
parentHacky attempt at catching SIGHUP and rotating the logfile around (diff)
downloadsynapse-929ae19d009d973a9c4947967d117b678f65068d.tar.xz
Merge pull request #280 from matrix-org/paul/sighup
Hacky attempt at catching SIGHUP and rotating the logfile around
Diffstat (limited to 'synapse/config/logger.py')
-rw-r--r--synapse/config/logger.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/synapse/config/logger.py b/synapse/config/logger.py
index fa542623b7..daca698d0c 100644
--- a/synapse/config/logger.py
+++ b/synapse/config/logger.py
@@ -21,6 +21,7 @@ import logging.config
 import yaml
 from string import Template
 import os
+import signal
 
 
 DEFAULT_LOG_CONFIG = Template("""
@@ -142,6 +143,19 @@ class LoggingConfig(Config):
                 handler = logging.handlers.RotatingFileHandler(
                     self.log_file, maxBytes=(1000 * 1000 * 100), backupCount=3
                 )
+
+                def sighup(signum, stack):
+                    logger.info("Closing log file due to SIGHUP")
+                    handler.doRollover()
+                    logger.info("Opened new log file due to SIGHUP")
+
+                # TODO(paul): obviously this is a terrible mechanism for
+                #   stealing SIGHUP, because it means no other part of synapse
+                #   can use it instead. If we want to catch SIGHUP anywhere
+                #   else as well, I'd suggest we find a nicer way to broadcast
+                #   it around.
+                if getattr(signal, "SIGHUP"):
+                    signal.signal(signal.SIGHUP, sighup)
             else:
                 handler = logging.StreamHandler()
             handler.setFormatter(formatter)