I was close to reporting a bug with logging handler + Progress #3097
-
This is just so nobody after me (or future me) needs to struggle with this: If you use the logging handler, you shouldn't pass a
Here's some code to reproduce the problem and solution: Codeimport logging
import time
from rich.console import Console
from rich.live import Live
from rich.logging import RichHandler
from rich.progress import BarColumn, Progress
console = Console()
logging.basicConfig(level="NOTSET", handlers=[RichHandler(level="NOTSET")])
logger = logging.getLogger('rich')
my_progress = Progress(
"{task.description}",
BarColumn(),
)
progress_context = Live(my_progress, refresh_per_second=10,
#console=console,
# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
)
my_job = my_progress.add_task("My task", total=10)
with progress_context:
for i in range(10):
logger.info('some log output')
time.sleep(1) I haven't tested other combinations of Live/Progress/Console/…, but maybe this is worth mentioning in the docs? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You don't need to use Live there, if you want the Progress bar. If you want logging and Progress to work together, the only requirement is that they use the same Console instance. You can pass console to the |
Beta Was this translation helpful? Give feedback.
You don't need to use Live there, if you want the Progress bar.
If you want logging and Progress to work together, the only requirement is that they use the same Console instance. You can pass console to the
RichHandler
constructor.