py.log using decorators for DRY

yoda nochiel at
Sat Oct 29 19:23:28 CEST 2005

I'm using py.log for logging and I find that I end up having the
following pattern emerge within my code (influenced by

def foo(**kwargs):
    #body form

This led me to believe that I could simplify that pattern with the
following idiom :

def logit (fn):
    decorator to enable logging of all tagged methods
        def decorator (**kwargs):
        # call a method named fn.func_name on log with kwargs
        #should be something like: log.func_name (kwargs)

    return decorator

I can then do add @logit to all my existing methods via a script
(there's a truck load of methods to tag):

def oldfoo () : pass

My question is in regards to the body form in the decorator.  How do I
call that method on the log object at runtime?

(ps.  I hope my question is clear $)

More information about the Python-list mailing list