make StreamHandler use tqdm.write
import logging
import sys
+import tqdm
+
from .factory import factory
from .path import log_file
+class TqdmLoggingHandler(logging.StreamHandler):
+ def __init__(self, level=logging.NOTSET):
+ super().__init__(level)
+
+ def emit(self, record):
+ try:
+ msg = self.format(record)
+ tqdm.tqdm.write(msg)
+ self.flush()
+ except (KeyboardInterrupt, SystemExit):
+ raise
+ except:
+ self.handleError(record)
+
+
+
def initialize():
CONFIG = factory.config()
# global log level for all messages
@@ -11,7 +29,7 @@ def initialize():
log_format = '%(asctime)s %(levelname)s:%(message)s'
# messages with info and above are printed to stdout
- console_handler = logging.StreamHandler(sys.stdout)
+ console_handler = TqdmLoggingHandler(sys.stdout)
console_handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
console_handler.setLevel(logging.INFO)
