mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Catch more unicode-related exceptions when trying to write logs to a file.
This commit is contained in:
parent
6d4ea07b72
commit
a538920df7
10
src/log.py
10
src/log.py
@ -127,15 +127,13 @@ class StdoutStreamHandler(logging.StreamHandler):
|
||||
class BetterFileHandler(logging.FileHandler):
|
||||
def emit(self, record):
|
||||
msg = self.format(record)
|
||||
if not hasattr(types, "UnicodeType"): #if no unicode support...
|
||||
self.stream.write(msg)
|
||||
self.stream.write(os.linesep)
|
||||
else:
|
||||
try:
|
||||
self.stream.write(msg)
|
||||
self.stream.write(os.linesep)
|
||||
except UnicodeError:
|
||||
except (UnicodeError, TypeError):
|
||||
try:
|
||||
self.stream.write(msg.encode("utf8"))
|
||||
except (UnicodeError, TypeError):
|
||||
self.stream.write(msg.encode("utf8").decode('ascii', 'replace'))
|
||||
self.stream.write(os.linesep)
|
||||
try:
|
||||
self.flush()
|
||||
|
Loading…
Reference in New Issue
Block a user