Web X.Y

Tips and tricks for development with Java, Python, Django, the Google Web Toolkit, and Linux.

Python: Using decorators with functools.wraps for automated logging and other goodies December 10, 2008

Filed under: python — adambossy @ 10:37 pm
Tags: , , ,

from functools import wraps

def magiclogging(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        print ‘Starting ‘ + func.func_name
        result = func(*args, **kwargs)
        print ‘Finishing ‘ + func.func_name
        return result
    return wrapper

More detail at Stack Overflow.

Even more at IBM DeveloperWorks.

Advertisement
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.