diff options
author | Erik Johnston <erik@matrix.org> | 2014-08-29 12:10:00 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2014-08-29 12:10:00 +0100 |
commit | 47fb286184dd27d8098af2fd24d22dd82205d3d5 (patch) | |
tree | 3e186226e18131b7c5d9ca89fdb4075667110c6d /synapse/util | |
parent | Expand architecture section to introduce room IDs, room aliases, user IDs, ev... (diff) | |
parent | Fix a couple of bugs in presence handler related to pushing updatesto the cor... (diff) | |
download | synapse-47fb286184dd27d8098af2fd24d22dd82205d3d5.tar.xz |
Merge branch 'presence_logging' into develop
Diffstat (limited to 'synapse/util')
-rw-r--r-- | synapse/util/logutils.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/synapse/util/logutils.py b/synapse/util/logutils.py index 021649071b..b94a749786 100644 --- a/synapse/util/logutils.py +++ b/synapse/util/logutils.py @@ -18,6 +18,8 @@ from inspect import getcallargs from functools import wraps import logging +import inspect +import traceback def log_function(f): @@ -65,4 +67,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 |