Skip to content

Instantly share code, notes, and snippets.

@pholat
Created November 9, 2021 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pholat/3c42722244daccdfd4ee4da65d2ac6bc to your computer and use it in GitHub Desktop.
Save pholat/3c42722244daccdfd4ee4da65d2ac6bc to your computer and use it in GitHub Desktop.
make tqdm work with logging
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)
@pholat
Copy link
Author

pholat commented Nov 17, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment