[docs] [issue17155] logging can raise UnicodeEncodeError
Kim
report at bugs.python.org
Thu Feb 21 03:07:00 CET 2013
Kim added the comment:
I'm running into similar issues with 2.6.7 and logging 0.4.9.6, where unicode strings are fine in print statements and codecs writes, but the same string is giving tracebacks for logging. If it's an education issue, I'm not finding the education I need ... :-/
import logging
import codecs
# Unicode string
i = u'\u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044a'
# Print statement is fine
print "hi, i'm the string in question in a print statement: %s" % i
# Codecs write is fine
with codecs.open('/tmp/utf8', 'w', 'utf-8') as f:
f.write(i)
# Logging gives a Traceback
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
handler = logging.FileHandler('/tmp/out', 'w', 'utf-8')
handler.setFormatter(logging.Formatter(u'[%(levelname)s] %(message)s'))
# I've also tried nixing setFormatter and going with the default
log.addHandler(handler)
log.debug(u"process_clusters: From CSV: %s", i)
# I've also tried a bare call to i, with and without the u in the message, and explicitly i.encode('utf8'); all Tracebacks.
----------
nosy: +kiminoa
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17155>
_______________________________________
More information about the docs
mailing list