Refactor logging to be a package, instead of a module

This commit is contained in:
Matthias
2023-04-09 16:48:18 +02:00
parent 818d18d4e0
commit ed57e7d43b
3 changed files with 45 additions and 41 deletions

View File

@@ -0,0 +1,26 @@
import sys
from logging import Handler
class FTStdErrStreamHandler(Handler):
def flush(self):
"""
Override Flush behaviour - we keep half of the configured capacity
otherwise, we have moments with "empty" logs.
"""
self.acquire()
try:
sys.stderr.flush()
finally:
self.release()
def emit(self, record):
try:
msg = self.format(record)
# Don't keep a reference to stderr - this can be problematic with progressbars.
sys.stderr.write(msg + '\n')
self.flush()
except RecursionError:
raise
except Exception:
self.handleError(record)