Created
February 16, 2016 17:39
-
-
Save tdpreece/51d1ba9c204debf17c04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def log_method_call(func): | |
def inner(*args, **kwargs): | |
try: | |
frame = inspect.currentframe() | |
stack_trace = inspect.getouterframes(frame) | |
stack_trace_relevant_parts = [ | |
" ".join((f[1], str(f[2]), f[4][0].strip())) | |
for f in stack_trace | |
] | |
pretty_stack_trace = "\n".join(stack_trace_relevant_parts) | |
msg = ( | |
'Method called with\nargs: {0}.\n' | |
'kwargs: {1}\nStack: \n{2}' | |
).format( | |
args, | |
kwargs, | |
pretty_stack_trace | |
) | |
logging.warning(msg) | |
except: | |
pass | |
return func(*args, **kwargs) | |
return inner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment