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 cannot handle Unicode logger names #69850
Comments
# coding=utf-8
import logging
logger = logging.getLogger(u'测试')
logger.error(u'测试') # these code will get an unexpected error |
I cannot reproduce, see below. Which exact version of Python are you using, and on what platform, and with what locale? $ more logtest9.py
# coding=utf-8
import logging logger = logging.getLogger(u'测试')
logger.error(u'测试')
$ python2.7 logtest9.py
No handlers could be found for logger "测试" |
sorry, i forgot this: logging.basicConfig(format='%(name)s %(message)s') the error raised at the processing of the format while the name is 'utf-8' encoded and the message is an unicode |
here is the case, sorry again for just typing it before and not testing it myself :) # coding=utf-8
import logging logging.basicConfig(format='%(name)s %(message)s') logger = logging.getLogger(u'测试')
logger.error(u'测试') btw, i'm using python2.7.10, mac osx 10.11, but i think this can effect all python2 |
$ cat x.py
# coding=utf-8
import logging
logging.basicConfig(format='%(name)s %(message)s')
logger = logging.getLogger(u'测试')
logger.error(u'测试') $ python2.7 x.py
Traceback (most recent call last):
File "/usr/lib64/python2.7/logging/__init__.py", line 859, in emit
msg = self.format(record)
File "/usr/lib64/python2.7/logging/__init__.py", line 732, in format
return fmt.format(record)
File "/usr/lib64/python2.7/logging/__init__.py", line 474, in format
s = self._fmt % record.__dict__
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 0: ordinal not in range(128)
Logged from file x.py, line 8 |
The problem is that logger names which are Unicode are not handled correctly, leading to the error. |
New changeset 512a628c683e by Vinay Sajip in branch '2.7': |
.format() doesn't look to me like the best place to encode the name. Why not doing that in record constructor? I don't want to add one try/except for each record field :-/ |
You're right, that's probably better. Perhaps I was too hasty ... |
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: