Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
imegeek opened this issue Dec 26, 2023 · 2 comments
Open

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

imegeek opened this issue Dec 26, 2023 · 2 comments

Comments

@imegeek
Copy link

imegeek commented Dec 26, 2023

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

Copy link

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

@imegeek imegeek closed this as completed Dec 27, 2023
@imegeek imegeek reopened this Dec 27, 2023
Copy link

I hope we solved your problem.

If you like using Rich, you might also enjoy Textual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant