Using logging with rich.progress #1173
-
Hi, import logging
import time
from rich.logging import RichHandler
from rich.progress import Progress
logging.basicConfig(handlers=[RichHandler()])
logger = logging.getLogger('rich')
with Progress(expand=True) as progress:
task = progress.add_task("Loading...",)
while not progress.finished:
logger.info('some log output')
progress.update(task, advance=10)
time.sleep(0.1) Unfortunately, the progress bar breaks on each log entry. How can I accomplish this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Your example didn't run as is because you didn't set the level on import logging
import time
from rich.logging import RichHandler
from rich.progress import Progress
logging.basicConfig(level="NOTSET", handlers=[RichHandler(level="NOTSET")])
logger = logging.getLogger('rich')
with Progress(expand=True) as progress:
task = progress.add_task("Loading...",)
while not progress.finished:
logger.info('some log output')
progress.update(task, advance=0.1)
time.sleep(1) |
Beta Was this translation helpful? Give feedback.
-
Hello, thanks for the tip logging.basicConfig(level="NOTSET", handlers=[RichHandler(level="NOTSET")])
logger = logging.getLogger('rich')
with console.status('Parsing...'):
for x in range(5):
logger.info('some log output')
sleep(1) I've tried example above with latest rich release (13.7.7) and unfortunately log messages breaks |
Beta Was this translation helpful? Give feedback.
Your example didn't run as is because you didn't set the level on
basicConfig
, but the following works as expected for me: