py.log using decorators for DRY



I'm using py.log for logging and I find that I end up having the
following pattern emerge within my code (influenced by
http://agiletesting.blogspot.com/2005/06/keyword-based-logging-with-py-library.html):


def foo(**kwargs):
log.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):


@logit
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 $)

.



Relevant Pages

  • Re: py.log using decorators for DRY
    ... > 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 logit: ... inside the body of callit. ...
    (comp.lang.python)
  • Re: Decorating instance methods
    ... I'm very interesting in using the decorator concept, ... def hello: ... How should I implement the function logging, when I want to use the ...
    (comp.lang.python)
  • Re: Decorating instance methods
    ... I'm very interesting in using the decorator concept, ... def hello: ... Entering a method. ... How should I implement the function logging, when I want to use the ...
    (comp.lang.python)
  • Re: Getting rid of "self."
    ... def __init__: ... > basis of information available at the time the decorator executes. ... I am content with declaring them like the selfless ... foo = _foo ...
    (comp.lang.python)
  • Re: python-style decorators
    ... def tak ... decorator at the bottom makes it easy to miss, ...
    (comp.lang.ruby)