Skip to content

Instantly share code, notes, and snippets.

@cppio
Last active December 23, 2018 23:05
Show Gist options
  • Select an option

  • Save cppio/abee165a2214586bffc9396706ad98d6 to your computer and use it in GitHub Desktop.

Select an option

Save cppio/abee165a2214586bffc9396706ad98d6 to your computer and use it in GitHub Desktop.
Simple logging function wrapper in python for easier debugging.
import functools
def wrap(wrapped):
@functools.wraps(wrapped)
def wrapper(*args, **kwds):
print("%s(%s)" % (wrapped.__name__, ", ".join(["%r" % i for i in args] + ["%s=%r" % i for i in kwds.items()])))
try:
ret = wrapped(*args, **kwds)
except BaseException as err:
print("%s >> %r" % (wrapped.__name__, err))
raise
print("%s -> %r" % (wrapped.__name__, ret))
return ret
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment