the ultimate logging facility for debugging code
vinay_sajip at yahoo.co.uk
Mon Jul 13 05:39:40 EDT 2009
On Jul 10, 10:39 am, Jean-Michel Pichavant <jeanmic... at sequans.com>
> Sorry for the dubious title :o). I was wandering if there is a standard
> (or reliable) python module that implements the following feature:
> >>>Recipe 198078: Wrapping method calls (meta-class example)
> >>>A metaclass is used to wrap all (or just some) methods forlogging
> purposes. The underlying mechanism can be used as well to check pre/post
> conditions, attribute access,... The basic point is, that the actual
> class must not be changed in any way to achive the desired effect.
> I had to adapt the code to some of my needs, but now it's almost
> working, by simply defining a metaclass for any of my class, I get the
> class methods calls logged with the instance that called the method, the
> method name, the call line in the file, the parameter **value** passed
> to the method and the returned value.
> It just saved me from hours of ipython interactive debugging with the
> old print way, and to beauty of it: I don't have to write any
> "self._log('Please log me')" line.
> As it is so useful, I bet there is a module that is doing this in a more
> reliable way that I did. Anyone has heard of it ?
Check out the Python Decorator Library: http://wiki.python.org/moin/PythonDecoratorLibrary
and you should be able to adapt what you find there to your needs.
More information about the Python-list