Last active
December 14, 2015 04:48
-
-
Save blaxter/5030477 to your computer and use it in GitHub Desktop.
log method decorator
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 logging | |
def log_method(fun): | |
""" | |
Example output (it will depend of you logging setup, obviously): | |
2013-02-25 16:13:58+0100 [-] DEBUG:root:--> Foo.update_bar | |
2013-02-25 16:13:58+0100 [-] DEBUG:root:<-- Foo.update_bar (0.052) | |
""" | |
def with_logging(self, *args, **kwargs): | |
method_name = '%s.%s' % (self.__class__.__name__, fun.__name__) | |
logging.debug('--> %s' % method_name) | |
start = time.time() | |
fun(self, *args, **kwargs) | |
logging.debug('<-- %s (%.3f)' % (method_name, time.time() - start)) | |
return with_logging |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment