Created
November 9, 2021 15:18
-
-
Save pholat/3c42722244daccdfd4ee4da65d2ac6bc to your computer and use it in GitHub Desktop.
make tqdm work with logging
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
log = logging.getLogger(__name__) | |
log.setLevel(logging.DEBUG) | |
class TqdmLoggingHandler(logging.Handler): | |
''' | |
required for pretty logs with tqdm | |
''' | |
def __init__(self, level=logging.NOTSET): | |
super().__init__(level) | |
def emit(self, record): | |
try: | |
msg = self.format(record) | |
tqdm.write(msg) | |
self.flush() | |
except Exception: | |
self.handleError(record) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
taken from here: https://stackoverflow.com/a/38739634/4239386
without it tqdm isn't "moved" with text logged by logging and logs look like a mess