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
12
src/log.py
12
src/log.py
@ -127,16 +127,14 @@ class StdoutStreamHandler(logging.StreamHandler):
|
|||||||
class BetterFileHandler(logging.FileHandler):
|
class BetterFileHandler(logging.FileHandler):
|
||||||
def emit(self, record):
|
def emit(self, record):
|
||||||
msg = self.format(record)
|
msg = self.format(record)
|
||||||
if not hasattr(types, "UnicodeType"): #if no unicode support...
|
try:
|
||||||
self.stream.write(msg)
|
self.stream.write(msg)
|
||||||
self.stream.write(os.linesep)
|
except (UnicodeError, TypeError):
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
self.stream.write(msg)
|
|
||||||
self.stream.write(os.linesep)
|
|
||||||
except UnicodeError:
|
|
||||||
self.stream.write(msg.encode("utf8"))
|
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:
|
try:
|
||||||
self.flush()
|
self.flush()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user