Last active
December 23, 2018 23:05
-
-
Save cppio/abee165a2214586bffc9396706ad98d6 to your computer and use it in GitHub Desktop.
Simple logging function wrapper in python for easier debugging.
This file contains hidden or 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
| 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