diff options
author | Mark Haines <mark.haines@matrix.org> | 2014-08-31 16:08:20 +0100 |
---|---|---|
committer | Mark Haines <mark.haines@matrix.org> | 2014-08-31 16:08:20 +0100 |
commit | 3eb45eba0e387dacb67158efe323f19731799c79 (patch) | |
tree | 79d942de91b8c9a940e787da9b4a329047139a80 /synapse/util | |
parent | Add store for server certificates and keys (diff) | |
parent | Add config tree to synapse. Add support for reading config from a file (diff) | |
download | synapse-3eb45eba0e387dacb67158efe323f19731799c79.tar.xz |
Merge branch 'develop' into server2server_tls
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 |