mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-27 21:22:39 +01:00
log: Simplify encoding in BetterFileHandler.
I don't think any these cases are useful anymore. Let's keep the last one anyway, just in case I'm wrong.
This commit is contained in:
parent
e972894b8a
commit
666acd9f1f
16
src/log.py
16
src/log.py
@ -127,20 +127,14 @@ class StdoutStreamHandler(logging.StreamHandler):
|
||||
|
||||
class BetterFileHandler(logging.FileHandler):
|
||||
def emit(self, record):
|
||||
msg = self.format(record)
|
||||
try:
|
||||
self.stream.write(msg)
|
||||
except (UnicodeError, TypeError):
|
||||
try:
|
||||
self.stream.write(msg.encode("utf8"))
|
||||
super().emit(record)
|
||||
except (UnicodeError, TypeError):
|
||||
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()
|
||||
msg = self.format(record)
|
||||
self.stream.write(repr(msg))
|
||||
self.stream.write(os.linesep)
|
||||
self.flush()
|
||||
except OSError as e:
|
||||
if e.args[0] == 28:
|
||||
print('No space left on device, cannot flush log.')
|
||||
|
Loading…
Reference in New Issue
Block a user