Last active
December 31, 2019 05:13
-
-
Save estshorter/45e1203b1968557d82c67e3ce833396e to your computer and use it in GitHub Desktop.
TqdmLoggingHandler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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