mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-27 21:22:39 +01:00
Catch more unicode-related exceptions when trying to write logs to a file.
This commit is contained in:
parent
6d4ea07b72
commit
a538920df7
12
src/log.py
12
src/log.py
@ -127,16 +127,14 @@ 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...
|
||||
try:
|
||||
self.stream.write(msg)
|
||||
self.stream.write(os.linesep)
|
||||
else:
|
||||
except (UnicodeError, TypeError):
|
||||
try:
|
||||
self.stream.write(msg)
|
||||
self.stream.write(os.linesep)
|
||||
except UnicodeError:
|
||||
self.stream.write(msg.encode("utf8"))
|
||||
self.stream.write(os.linesep)
|
||||
except (UnicodeError, TypeError):
|
||||
self.stream.write(msg.encode("utf8").decode('ascii', 'replace'))
|
||||
self.stream.write(os.linesep)
|
||||
try:
|
||||
self.flush()
|
||||
except OSError as e:
|
||||
|
Loading…
Reference in New Issue
Block a user