rich icon indicating copy to clipboard operation
rich copied to clipboard

Why this happening when i set: RichHandler(console=Console())

Open imegeek opened this issue 6 months ago • 2 comments

I was trying to set color to my custom logging label everything worked fine but when i was using rich.progress then i saw this weird printing mistake (overflow).

import logging
from rich.logging import RichHandler
from time import sleep
from rich.theme import Theme
from rich.console import Console

FORMAT = "%(message)s"
logging.basicConfig(
    level="NOTSET", format=FORMAT, datefmt="[%X]", handlers=[RichHandler(
        console=Console(theme=Theme({"logging.level.success": "green"}))
    )]
)

log = logging.getLogger("rich")
log.info("Hello, World!")

#log.error("[bold red blink]Server is shutting down![/]", extra={"markup": True})

#log.error("123 will not be highlighted", extra={"highlighter": None})

logging.addLevelName(25, "SUCCESS")

import time
from rich.progress import Progress

with Progress() as progress:
    task = progress.add_task("Working", total=None)
    for i in range(0,100):
        if i < 30:
            logging.log(25, i+1)
        elif i > 30:
            log.warning(i+1)
        elif i >= 30 and i < 50:
            log.error(i+1)
        elif i >= 50 and i < 70:
            log.debug(i+1)
        elif i >= 70:
            log.critical(i+1)
        sleep(0.05)

image

imegeek avatar Dec 26 '23 09:12 imegeek

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

github-actions[bot] avatar Dec 26 '23 09:12 github-actions[bot]

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

github-actions[bot] avatar Dec 27 '23 13:12 github-actions[bot]