
logutils - issue #2
logutils.colorize.ColorizingStreamHandler has no encoding support
What steps will reproduce the problem? 1. dictConfig(config) 2. log = logging.getLogger("channel") 3. log.debug(u'Some unicode string with some śćźół chars')
What is the expected output? What do you see instead? Instead you get: <code> Traceback (most recent call last): File "build/bdist.linux-x86_64/egg/logutils/colorize.py", line 64, in emit File "build/bdist.linux-x86_64/egg/logutils/colorize.py", line 87, in output_colorized UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 78: ordinal not in range(128) </code>
What version of the product are you using? On what operating system? logutils 0.3 python 2.6.5 CentOS 5.5
Please provide any additional information below.
Logutils completly ignores encoding when emit()ing.
Python 2.6 & 2.7 behave correctly, take a look at emit() method of StreamHandler
emit() in py2.7.1: <code> try: msg = self.format(record) stream = self.stream fs = "%s\n" if not _unicode: #if no unicode support... stream.write(fs % msg) else: try: if (isinstance(msg, unicode) and getattr(stream, 'encoding', None)): ufs = fs.decode(stream.encoding) try: stream.write(ufs % msg) except UnicodeEncodeError: #Printing to terminals sometimes fails. For example, #with an encoding of 'cp1251', the above write will #work if written to a stream opened or wrapped by #the codecs module, but fail when writing to a #terminal even when the codepage is set to cp1251. #An extra encoding step seems to be needed. stream.write((ufs % msg).encode(stream.encoding)) else: stream.write(fs % msg) except UnicodeError: stream.write(fs % msg.encode("UTF-8")) self.flush() except (KeyboardInterrupt, SystemExit): raise except: self.handleError(record) </code>
the _unicode is: <code> try: unicode _unicode = True except NameError: _unicode = False </code>
Comment #1
Posted on Jan 16, 2012 by Swift Lion(No comment was entered for this change.)
Comment #2
Posted on Jan 24, 2013 by Swift LionThe change for this is done now, and released in 0.3.3.
Status: Fixed
Labels:
Type-Defect
Priority-Medium