classification
Title: logging don't encode Unicode message correctly.
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: amaury.forgeotdarc, inada.naoki, vinay.sajip
Priority: normal Keywords: patch

Created on 2009-04-16 06:46 by inada.naoki, last changed 2009-04-16 19:17 by vinay.sajip. This issue is now closed.

Files
File name Uploaded Description Edit
logging_init.diff inada.naoki, 2009-04-16 06:58 logging/__init__.py
logging_encoding.patch amaury.forgeotdarc, 2009-04-16 12:31
Messages (3)
msg86015 - (view) Author: INADA Naoki (inada.naoki) * (Python committer) Date: 2009-04-16 06:45
>>> logging.error(u'あ')
ERROR:root:縺・
>>> sys.stderr.encoding
'cp932'

This bug is introduced by following commit.
http://svn.python.org/view/python/branches/release26-
maint/Lib/logging/__init__.py?r1=68830&r2=69448
msg86025 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-04-16 12:31
I think that in r69448, the test does not match the code:
codecs.getwriter('cp1251') has no attribute 'encoding', and no function
in test_logging ever pass a stream with an explicit encoding.

Also, the test in emit() should be reversed, otherwise msg.encode() is
called only when msg is a 8bit string. And in this case, a unicode
string should be passed to the stream.

See attached patch.
The codecs.getwriter should probably grow an 'encoding' attribute
automatically, but this is another issue.
msg86039 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2009-04-16 19:17
Fix checked into trunk and release26-maint.
History
Date User Action Args
2009-04-16 19:17:39vinay.sajipsetstatus: open -> closed
resolution: fixed
messages: + msg86039
2009-04-16 12:31:59amaury.forgeotdarcsetfiles: + logging_encoding.patch

nosy: + amaury.forgeotdarc, vinay.sajip
messages: + msg86025

assignee: vinay.sajip
2009-04-16 06:58:08inada.naokisetfiles: + logging_init.diff
2009-04-16 06:55:36inada.naokisetfiles: - logging_init.diff
2009-04-16 06:46:29inada.naokicreate