New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging to file does not accept UTF16 #63466
Comments
The following code reproduces the error: import logging
logging.root.addHandler(logging.FileHandler(filename='test.log',encoding='UTF16'))
logging.error( u'b\u0142\u0105d') I think the problem is in the line as Python can't really handle the following code: fs = "%s\n" |
The example works fine on Python3: localhost$ python3
Python 3.3.2 (default, Aug 23 2013, 19:00:04)
[GCC 4.8.1 20130603 (Red Hat 4.8.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging
>>> logging.root.addHandler(logging.FileHandler(filename='test.log',encoding='UTF16'))
>>> logging.error( u'b\u0142\u0105d')
>>> localhost$ hexdump test.log |
I don't understand the purpose of fs.decode(stream.encoding): why not directly using ufs=u'%s\n"? @pawel: Can you please try to replace ufs=fs.decode(stream.encoding) with ufs=u'%s\n'? |
Hi Victor. Your fix works, but actually using simply ufs='%s\n' also seem to work, as So I would suggest dropping ufs completely, and changing the two occurences to fs. It works - I checked. Maybe some code refactoring could be done then, as I'm not sure if the two nested 'try' statements are needed in such case. |
Btw I also don't see the purspose of fs.decode(stream.encoding), as it should rather be encoded and not decoded... |
Hi, here the patch to fix this bug on Python 2.7 with a test suite. |
patch_utf16 looks good to me. |
New changeset e94e29dab32c by Victor Stinner in branch '2.7': |
This bug is specific to Python 2. I should now be fixed, thanks Paweł for the report and Natal for the patch. @natal: Could you please sign the Contributor Agreement for next contributions? |
Cool - looks good to me as well. Thanks guys. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: