summary refs log tree commit diff
path: root/synapse/config/logger.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-11-14 11:46:07 +0000
committerErik Johnston <erik@matrix.org>2014-11-14 11:46:07 +0000
commitb8eca1ffbf697b968acd0e3abc0341ca134dc6a0 (patch)
tree64b1eb1540f1eff147fb58ac9e85fc64920a49ad /synapse/config/logger.py
parentUse modelService to access room member power levels rather than RoomController. (diff)
parentMerge branch 'develop' into request_logging (diff)
downloadsynapse-b8eca1ffbf697b968acd0e3abc0341ca134dc6a0.tar.xz
Merge pull request #13 from matrix-org/request_logging
Request logging
Diffstat (limited to 'synapse/config/logger.py')
-rw-r--r--synapse/config/logger.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/synapse/config/logger.py b/synapse/config/logger.py
index 05611d02f7..8566296433 100644
--- a/synapse/config/logger.py
+++ b/synapse/config/logger.py
@@ -14,7 +14,7 @@
 # limitations under the License.
 
 from ._base import Config
-
+from synapse.util.logcontext import LoggingContextFilter
 from twisted.python.log import PythonLoggingObserver
 import logging
 import logging.config
@@ -46,7 +46,8 @@ class LoggingConfig(Config):
 
     def setup_logging(self):
         log_format = (
-            '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s'
+            "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s"
+            " - %(message)s"
         )
         if self.log_config is None:
 
@@ -54,13 +55,20 @@ class LoggingConfig(Config):
             if self.verbosity:
                 level = logging.DEBUG
 
-               # FIXME: we need a logging.WARN for a -q quiet option
+            # FIXME: we need a logging.WARN for a -q quiet option
+            logger = logging.getLogger('')
+            logger.setLevel(level)
+            formatter = logging.Formatter(log_format)
+            if self.log_file:
+                handler = logging.FileHandler(self.log_file)
+            else:
+                handler = logging.StreamHandler()
+            handler.setFormatter(formatter)
+
+            handler.addFilter(LoggingContextFilter(request=""))
 
-            logging.basicConfig(
-                level=level,
-                filename=self.log_file,
-                format=log_format
-            )
+            logger.addHandler(handler)
+            logger.info("Test")
         else:
             logging.config.fileConfig(self.log_config)