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:
self.stream.write(msg.encode("utf8"))
except (UnicodeError, TypeError):
self.stream.write(msg.encode("utf8").decode('ascii', 'replace'))
try:
self.stream.write(msg.encode("utf8").decode('ascii', 'replace'))
except (UnicodeError, TypeError):
self.stream.write(repr(msg))
self.stream.write(os.linesep)
try:
self.flush()