[Twisted-Python] Re: [Twisted-commits] r14614 - Describe log.debug, and 'printed' and 'debug' log dict items.

Jp Calderone exarkun at divmod.com
Tue Oct 4 15:27:30 EDT 2005

On Tue, 4 Oct 2005 10:00:58 -0700, Scott Lamb <slamb at slamb.org> wrote:
>On Oct 4, 2005, at 12:20 AM, Nicola Larosa wrote:
>>Also, a few words to the effect of *why* it should be deprecated  would be
>>useful. We use it quite a lot, and I'd appreciate a few comments.
>Me, too, me too.
>In my day job, I develop a lot of Java code. We have the luxury of  granular 
>logging. I can switch, on a per-class basis, the output  level to trace, 
>debug, warn, error, or fatal. That's handy.
>In Twisted, I see log.msg(), log.debug(), and log.err(). Why is one  of 
>these levels going away? Is it just not normal to use logging for 
>debugging? What do you do instead?

One of the functions is going away.  A level isn't going away, because twisted.python.log does not have the notion of "levels" present in other logging systems.

What you can log with twisted.python.log is an event.  A very common kind of event is a byte string - log.msg is often used to emit one of these, but it can emit any kind of event.  Another common event corresponds to an error and is represented by a twisted.python.failure.Failure instance - log.err is a convenience function to construct a Failure from the current Python exception state and emit it.  log.debug is this warty thing that emits a string but also attaches {"debug": 1} to it.  This is completely ignored by the log observer Twisted actually includes.

To emphasize that point, in the default configuration, log.msg() does exactly the same thing as log.debug().

So, it's pointless.  The functionality might be useful, although I've never found it such (print is pretty easy to use, and Python is too slow to leave in debug messages after debugging is finished).  As Itamar pointed out in his post, we have some ideas about providing a lot more structure for the event system, but we haven't gotten around to implementing it.  Once we do, there will be much richer facilities for this kind of behavior.


More information about the Twisted-Python mailing list