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

Discussão em 'Python' iniciado por Stack, Novembro 27, 2024.

  1. Stack

    Stack Membro Participativo

    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)


    see image here: https://github.com/Textualize/rich/assets/63346676/a37af0c7-02b4-4509-be9a-8b09c8b8db70)

    i don't found any solution of this topic.

    Continue reading...

Compartilhe esta Página