You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When logging invalid utf8 with RichHandler, the logging breaks completely. Even when applying the provided fix. MWE:
importloggingfromrich.loggingimportRichHandlerlogger=logging.getLogger()
logger.setLevel("INFO")
# console_handler = logging.StreamHandler() # This worksconsole_handler=RichHandler() # This throws an exceptionconsole_handler.setLevel("INFO")
logger.handlers= [console_handler]
invalid_output="\udcf1"logger.info(invalid_output)
This is the output:
$ PYTHONIOENCODING=utf-8 python testrich.py
--- Logging error ---
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/rich/logging.py", line 170, in emit
self.console.print(log_renderable)
File "/usr/lib/python3/dist-packages/rich/console.py", line 1673, in print
with self:
File "/usr/lib/python3/dist-packages/rich/console.py", line 865, in __exit__
self._exit_buffer()
File "/usr/lib/python3/dist-packages/rich/console.py", line 823, in _exit_buffer
self._check_buffer()
File "/usr/lib/python3/dist-packages/rich/console.py", line 2060, in _check_buffer
self.file.write(text)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcf1' in position 60: surrogates not allowed
*** You may need to add PYTHONIOENCODING=utf-8 to your environment ***
Call stack:
File "/home/adrian/git/New-Solvency/testrich.py", line 15, in <module>
logger.info(invalid_output)
File "/usr/lib/python3.12/logging/__init__.py", line 1539, in info
self._log(INFO, msg, args, **kwargs)
File "/usr/lib/python3.12/logging/__init__.py", line 1684, in _log
self.handle(record)
File "/usr/lib/python3.12/logging/__init__.py", line 1700, in handle
self.callHandlers(record)
File "/usr/lib/python3.12/logging/__init__.py", line 1762, in callHandlers
hdlr.handle(record)
File "/usr/lib/python3.12/logging/__init__.py", line 1028, in handle
self.emit(record)
File "/usr/lib/python3/dist-packages/rich/logging.py", line 172, in emit
self.handleError(record)
Message: '\udcf1'
It looks like a duplicate of #212, but I'm opening a separate bug because as you can see, the error message is suggesting to set PYTHONIOENCODING=utf-8, but it doesn't work. I don't find this to be an acceptable solution anyway, because I cannot request my users to set this variable. There should be some graceful failure mode.
Platform
Click to expand
I'm using Debian sid. My terminal is Konsole. My shell is zsh.
Describe the bug
When logging invalid utf8 with
RichHandler
, the logging breaks completely. Even when applying the provided fix. MWE:This is the output:
It looks like a duplicate of #212, but I'm opening a separate bug because as you can see, the error message is suggesting to set
PYTHONIOENCODING=utf-8
, but it doesn't work. I don't find this to be an acceptable solution anyway, because I cannot request my users to set this variable. There should be some graceful failure mode.Platform
Click to expand
I'm using Debian sid. My terminal is Konsole. My shell is zsh.
The text was updated successfully, but these errors were encountered: