[Twisted-Python] Twisted.logger on windows max recursion depth exceeded

John Aherne johnaherne at rocs.co.uk
Sun Jan 7 02:42:52 MST 2018


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

Yes. Must be the weather :-).

But very helpful from my point of view as I've just started to look at it.

Well I guessed that printing inside the observer was not a good idea.

But I could not see why this one showed the problem

log = Logger(namespace="jah_test5")
globalLogPublisher.addObserver(FileLogObserver(
DailyLogFile.fromFullPath('c:\\logs\\my_log9.log'), jahlog))

But this one did not

f = FileLogObserver(DailyLogFile.fromFullPath('c:\\logs\\my_log6.log'),
jahlog)
log = Logger(observer=f, namespace="klein_test")

I was assuming they would both add an observer to globalLogObserver at some
point.

And if klein was the culprit it would have the same problem with both.

Anyway I only needed the print statements while I checked out what was
turning up in the event.

Thanks.

John


On Sun, Jan 7, 2018 at 7:27 AM, Glyph <glyph at twistedmatrix.com> wrote:

> Hi John,
>
> Lots of interest in logging this week for some reason :-).
>
> On Jan 6, 2018, at 4:38 AM, John Aherne <johnaherne at 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 at twistedmatrix.com
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>


-- 
*John Aherne*




*www.rocs.co.uk <http://www.rocs.co.uk>*
020 7223 7567
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20180107/79ec3dad/attachment-0002.html>


More information about the Twisted-Python mailing list