Add another fallback to log emitting in case of unicode-related error.

This commit is contained in:
Valentin Lorentz 2016-03-20 12:56:33 +01:00
parent 93feb71b66
commit b64926814b

View File

@ -133,7 +133,10 @@ class BetterFileHandler(logging.FileHandler):
try: try:
self.stream.write(msg.encode("utf8")) self.stream.write(msg.encode("utf8"))
except (UnicodeError, TypeError): except (UnicodeError, TypeError):
try:
self.stream.write(msg.encode("utf8").decode('ascii', 'replace')) self.stream.write(msg.encode("utf8").decode('ascii', 'replace'))
except (UnicodeError, TypeError):
self.stream.write(repr(msg))
self.stream.write(os.linesep) self.stream.write(os.linesep)
try: try:
self.flush() self.flush()