[Twisted-Python] Twisted logger changes

Dear list, I've tried running Twisted 15.2.1 with my old library, and I am getting an exception, that I haven't seen before (with Twisted 14.0.0): File "/usr/local/lib/python2.7/dist-packages/txthings/coap.py", line 1338, in sendResponse print "Token: %s" % (response.token) File "/usr/local/lib/python2.7/dist-packages/twisted/logger/_io.py", line 163, in write string = string.decode(self._encoding) File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) exceptions.UnicodeDecodeError: 'utf8' codec can't decode byte 0xae in position 7: invalid start byte Although it is triggered by simple print, it seems to be caused by logging. Does new logging framework need any configuration to stay compatible with the old one? Best regards Maciej Wasilak

Although logger is reacting to this in a bad way, and that is a bug, your program has a bug too: you are printing to a text file (which is what stdout is when it is redirected to a log) by using binary data. python 3 will mangle your output if you try to do this, so you should restrict your program to unicode if you intend to redirect stdout to a logger. Here's a very simple example which provokes the same bad behavior: import sys from twisted.logger import globalLogBeginner, textFileLogObserver globalLogBeginner.beginLoggingTo([textFileLogObserver(sys.stdout)]) print(b"Testing testing, one \xae two.") The equivalent in old-style logging would be: import sys from twisted.python.log import startLogging startLogging(sys.stdout) print(b"Testing testing, one \xae two.") Therefore this is a regression in the new logging system. I've filed it as a bug, here: <https://twistedmatrix.com/trac/ticket/7933 <https://twistedmatrix.com/trac/ticket/7933>>. In the future, I would encourage you to take advantage of the pre-release testing period to discover issues like this, since it would have been nice to know about this before the final release went out ;-). (Not to say this is your fault though, this is totally our bug, and I'm surprised we didn't catch it given all the other similar stuff we caught before the release.) -glyph

Dear Glyph, 2015-06-09 8:09 GMT+02:00 Glyph <glyph@twistedmatrix.com>:
Thank you for your help. I'll update my library, and replace all occurences of print with log.msg("").
I've found the problem only after installing PyPI package with 'twisted>=14.0.0' dependency on new system. Sorry! Thanks again for excellent work! Best Regards Maciej Wasilak

No need to apologize! There's an implied question here, which is: is there any way we can make the prerelease process work better for you? Some channel where we could communicate it where you'd notice? Some way to fit it into your workflow?
Thanks again for excellent work!
Thank you for reporting this issue!

Although logger is reacting to this in a bad way, and that is a bug, your program has a bug too: you are printing to a text file (which is what stdout is when it is redirected to a log) by using binary data. python 3 will mangle your output if you try to do this, so you should restrict your program to unicode if you intend to redirect stdout to a logger. Here's a very simple example which provokes the same bad behavior: import sys from twisted.logger import globalLogBeginner, textFileLogObserver globalLogBeginner.beginLoggingTo([textFileLogObserver(sys.stdout)]) print(b"Testing testing, one \xae two.") The equivalent in old-style logging would be: import sys from twisted.python.log import startLogging startLogging(sys.stdout) print(b"Testing testing, one \xae two.") Therefore this is a regression in the new logging system. I've filed it as a bug, here: <https://twistedmatrix.com/trac/ticket/7933 <https://twistedmatrix.com/trac/ticket/7933>>. In the future, I would encourage you to take advantage of the pre-release testing period to discover issues like this, since it would have been nice to know about this before the final release went out ;-). (Not to say this is your fault though, this is totally our bug, and I'm surprised we didn't catch it given all the other similar stuff we caught before the release.) -glyph

Dear Glyph, 2015-06-09 8:09 GMT+02:00 Glyph <glyph@twistedmatrix.com>:
Thank you for your help. I'll update my library, and replace all occurences of print with log.msg("").
I've found the problem only after installing PyPI package with 'twisted>=14.0.0' dependency on new system. Sorry! Thanks again for excellent work! Best Regards Maciej Wasilak

No need to apologize! There's an implied question here, which is: is there any way we can make the prerelease process work better for you? Some channel where we could communicate it where you'd notice? Some way to fit it into your workflow?
Thanks again for excellent work!
Thank you for reporting this issue!
participants (3)
-
Glyph
-
Glyph Lefkowitz
-
Maciej Wasilak