Hi John,

Lots of interest in logging this week for some reason :-).

> On Jan 6, 2018, at 4:38 AM, John Aherne <johnahe...@rocs.co.uk 
> <mailto:johnahe...@rocs.co.uk>> wrote:
> 
> If I comment out the print statements all seems to work correctly.
> 
> I assume I am doing something wrong or something I should not be trying to 
> do. But I can't work out what causes the 2 setups to behave so differently.

The issue here is that klein.run() is initializing the (old-style) logging 
system; that initialization, among other things, includes replacing sys.stdout 
and sys.stderr with files that will emit log messages rather than write 
directly.

`print` debugging of log observers is therefore always somewhat risky since 
many ways of initializing the logging system will do this.

Perhaps the logging system should be a bit more defensive about observers 
emitting messages; however, for the time being, if you want to do `print` 
debugging of a log observer, at the top of your file do something like

from sys import stderr as DEBUG

and then everywhere you have a call to the 'print' function, use the 'file' 
kwarg:

print('ITEM', event[item], file=DEBUG)

I hope this is helpful,

-g
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to