Created
June 23, 2011 22:57
-
-
Save j2labs/1043833 to your computer and use it in GitHub Desktop.
logging_decorator_example.py
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
| #!/usr/bin/env python | |
| import logging | |
| import time | |
| logging.basicConfig(level=logging.DEBUG, | |
| filename='whatevz.log') | |
| def log_runtime(method): | |
| def wrapper(*a, **kw): | |
| start = time.time() | |
| retval = method(*a, **kw) | |
| finish = time.time() | |
| logging.debug('%s took %s seconds to run' % (method.__name__, | |
| (finish - start))) | |
| return retval | |
| return wrapper | |
| @log_runtime | |
| def foo(): | |
| print 'foo' | |
| if __name__ == "__main__": | |
| foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment