Skip to content

Instantly share code, notes, and snippets.

@tdpreece
Created February 16, 2016 17:39
Show Gist options
  • Save tdpreece/51d1ba9c204debf17c04 to your computer and use it in GitHub Desktop.
Save tdpreece/51d1ba9c204debf17c04 to your computer and use it in GitHub Desktop.
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