question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there any way of using loguru.logger with tqdm?

I’ve tried many solutions but nothing printed the progress bar of tqdm in one line. In all solutions that I tried, each update of tqdm progress bar was a new line. For example:

  0%|           | 0/100 [00:00<?, ?it/s]
  1%|1         | 1/100 [00:00<00:09,  9.98it/s]
  2%|2         | 2/100 [00:00<00:09,  9.97it/s]
  3%|3         | 3/100 [00:00<00:09,  9.97it/s]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

9reactions
Delgancommented, Feb 20, 2020

@vmvz Yeah, sorry, this has been changed in v0.4.0 (the .add() method no longer automatically pass extra arguments to sink, because this was prone to error).

Instead, on should use this:

logger.add(lambda msg: tqdm.write(msg, end=""))

I updated the documentation consequently.

4reactions
Delgancommented, Oct 8, 2019

Hi.

Did you try to replace the default handler with tqdm.write()? It seems to work fine for displaying the progress bar:

from tqdm import tqdm
from loguru import logger
import time

logger.remove()
logger.add(tqdm.write, end="")

logger.info("Initializing")

for x in tqdm(range(100)):
    logger.info("Iterating #{}", x)
    time.sleep(0.1)
Read more comments on GitHub >

github_iconTop Results From Across the Web

tqdm/tqdm: A Fast, Extensible Progress Bar for Python and ...
tqdm derives from the Arabic word taqaddum (تقدّم) which can mean "progress," and is an abbreviation for "I love you so much" in...
Read more >
tqdm documentation
tqdm means "progress" in Arabic (taqadum, تقدّم) and is an abbreviation for "I love you so much" in Spanish (te quiero demasiado). Instantly...
Read more >
Python | How to make a terminal progress bar using tqdm
Usage. Using tqdm is very simple, you just need to add your code between tqdm() after importing the library in your code. You...
Read more >
How to Use Progress Bars in Python? | tqdm and ...
tqdm is a library in Python which is used for creating Progress Meters or Progress Bars. In this article learn how to create...
Read more >
tqdm Tutorial
tqdm is a Python library which is used for creating a progress bar. It is typically used to display the progress of a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found