py.log using decorators for DRY
- From: "yoda" <nochiel@xxxxxxxxx>
- Date: 29 Oct 2005 10:23:28 -0700
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 $)
.
- Follow-Ups:
- Re: py.log using decorators for DRY
- From: Alex Martelli
- Re: py.log using decorators for DRY
- Prev by Date: Re: Automatic binding of **kwargs to variables
- Next by Date: Re: Expanding Python as a macro language
- Previous by thread: Building 2.4.2 on OpenBSD 3.8
- Next by thread: Re: py.log using decorators for DRY
- Index(es):
Relevant Pages
|