Created
March 2, 2010 20:33
-
-
Save ynadji/319900 to your computer and use it in GitHub Desktop.
function-level logging with python
This file contains 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 | |
# log everything | |
logging.basicConfig(level=logging.DEBUG) | |
# kickass logging for function entry/exit | |
class loggerize(object): | |
def __init__(self, f): | |
self.f = f | |
def __call__(self, *a, **kw): | |
logging.debug("entering " + self.f.__name__) | |
x = self.f(*a, **kw) | |
logging.debug("exiting " + self.f.__name__) | |
return x | |
@loggerize | |
def foo(): | |
"""will log when execution enters/exits function foo""" | |
return 1 + 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment