This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author methane
Recipients SilentGhost, jonathan-lp, methane, paul.moore, steve.dower, tim.golden, vinay.sajip, zach.ware
Date 2019-06-13.00:10:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1560384625.29.0.702302599764.issue37111@roundup.psfhosted.org>
In-reply-to
Content
> What logging does when UnicodeEncodeError is happened?

Hm, it seems logging does best job, show enough information to stderr.

But sometime, Python is embedded in web servers and there is no stderr.  pythonw.exe may not have stderr too....

I still feel backslashreplace is better default error handler.  But it's not strong opinion and it shouldn't block this issue.  Go ahead.


$ cat x.py
import logging

logging.basicConfig(filename="mylog.txt")
msg = "hello, はろー"
logging.error(msg)

$ LC_ALL=en_US.US-ASCII python3 x.py
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 1037, in emit
    stream.write(msg + self.terminator)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 18-20: ordinal not in range(128)
Call stack:
  File "x.py", line 5, in <module>
    logging.error(msg)
Message: 'hello, \u306f\u308d\u30fc'
Arguments: ()
History
Date User Action Args
2019-06-13 00:10:25methanesetrecipients: + methane, paul.moore, vinay.sajip, tim.golden, SilentGhost, zach.ware, steve.dower, jonathan-lp
2019-06-13 00:10:25methanesetmessageid: <1560384625.29.0.702302599764.issue37111@roundup.psfhosted.org>
2019-06-13 00:10:25methanelinkissue37111 messages
2019-06-13 00:10:25methanecreate