summary refs log tree commit diff
path: root/synapse/util
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2014-08-28 14:58:51 +0100
committerErik Johnston <erik@matrix.org>2014-08-28 14:58:51 +0100
commitb8b52ca09d76e14854535df9a93b25096fcbd36a (patch)
tree3e9f53ff58047e43dc85a9ef636ae05c21660619 /synapse/util
parentFix bug where we used UserID objects instead of strigns (diff)
downloadsynapse-b8b52ca09d76e14854535df9a93b25096fcbd36a.tar.xz
Add logging to try and figure out what is going on with the presence stuff
Diffstat (limited to 'synapse/util')
-rw-r--r--synapse/util/logutils.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/synapse/util/logutils.py b/synapse/util/logutils.py
index 9270a1790b..86a41ddc8e 100644
--- a/synapse/util/logutils.py
+++ b/synapse/util/logutils.py
@@ -17,6 +17,8 @@
 from inspect import getcallargs
 
 import logging
+import inspect
+import traceback
 
 
 def log_function(f):
@@ -63,4 +65,55 @@ def log_function(f):
 
         return f(*args, **kwargs)
 
+    wrapped.__name__ = func_name
+    return wrapped
+
+
+def trace_function(f):
+    func_name = f.__name__
+    linenum = f.func_code.co_firstlineno
+    pathname = f.func_code.co_filename
+
+    def wrapped(*args, **kwargs):
+        name = f.__module__
+        logger = logging.getLogger(name)
+        level = logging.DEBUG
+
+        s = inspect.currentframe().f_back
+
+        to_print = [
+            "\t%s:%s %s. Args: args=%s, kwargs=%s" % (
+                pathname, linenum, func_name, args, kwargs
+            )
+        ]
+        while s:
+            if True or s.f_globals["__name__"].startswith("synapse"):
+                filename, lineno, function, _, _ = inspect.getframeinfo(s)
+                args_string = inspect.formatargvalues(*inspect.getargvalues(s))
+
+                to_print.append(
+                    "\t%s:%d %s. Args: %s" % (
+                        filename, lineno, function, args_string
+                    )
+                )
+
+            s = s.f_back
+
+        msg = "\nTraceback for %s:\n" % (func_name,) + "\n".join(to_print)
+
+        record = logging.LogRecord(
+            name=name,
+            level=level,
+            pathname=pathname,
+            lineno=lineno,
+            msg=msg,
+            args=None,
+            exc_info=None
+        )
+
+        logger.handle(record)
+
+        return f(*args, **kwargs)
+
+    wrapped.__name__ = func_name
     return wrapped