the ultimate logging facility for debugging code

  • Thread starter Jean-Michel Pichavant
  • Start date
J

Jean-Michel Pichavant

Greetings,

Sorry for the dubious title :eek:). I was wandering if there is a standard
(or reliable) python module that implements the following feature:

http://code.activestate.com/recipes/198078/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 ?

Jean-Michel
 
V

Vinay Sajip

Greetings,

Sorry for the dubious title :eek:). I was wandering if there is a standard
(or reliable) python module that implements the following feature:

http://code.activestate.com/recipes/198078/
 >>>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 ?

Jean-Michel

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.

Regards,

Vinay Sajip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top