Skip to content

Instantly share code, notes, and snippets.

@ynadji
Created March 2, 2010 20:33
Show Gist options
  • Save ynadji/319900 to your computer and use it in GitHub Desktop.
Save ynadji/319900 to your computer and use it in GitHub Desktop.
function-level logging with python
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