Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created June 23, 2011 22:57
Show Gist options
  • Select an option

  • Save j2labs/1043833 to your computer and use it in GitHub Desktop.

Select an option

Save j2labs/1043833 to your computer and use it in GitHub Desktop.
logging_decorator_example.py
#!/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