Skip to content

Instantly share code, notes, and snippets.

@estshorter
Last active December 31, 2019 05:13
Show Gist options
  • Save estshorter/45e1203b1968557d82c67e3ce833396e to your computer and use it in GitHub Desktop.
Save estshorter/45e1203b1968557d82c67e3ce833396e to your computer and use it in GitHub Desktop.
TqdmLoggingHandler
import logging
import tqdm
class TqdmLoggingHandler(logging.Handler):
# https://stackoverflow.com/questions/38543506/change-logging-print-function-to-tqdm-write-so-logging-doesnt-interfere-wit
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 Exception:
self.handleError(record)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment