Skip to content

🏂 - rich logging (provide clarity to downstream devs seeing errors in console) #7524

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

johndpope
Copy link

fellow devs watching PRs do check this - just a few lines of code changes.

Screenshot from 2025-04-07 21-52-26

@johndpope johndpope changed the title 🏂 - rich logging 🏂 - rich logging (provide clarity to downstream devs seeing errors in console) Apr 7, 2025
@city96
Copy link
Contributor

city96 commented Apr 13, 2025

I've had a simpler version of this for a while, which was mostly based on the code from sd_scripts

You need to remove the default logging handler(s) to avoid the double-logging shown in your screenshot.
The code below just works as a custom node and sets up the handler globally when it gets loaded, which is mostly enough for my usecase.

import logging
from rich.console import Console
from rich.logging import RichHandler

if logging.root.handlers:
    for handler in logging.root.handlers[:]:
        logging.root.removeHandler(handler)

formatter = logging.Formatter(fmt="%(message)s", datefmt="%Y-%m-%d %H:%M:%S")
new_handler = RichHandler(console=Console(stderr=True))
new_handler.setFormatter(formatter)
logging.root.addHandler(new_handler)

NODE_CLASS_MAPPINGS = {}

image

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

Successfully merging this pull request may close these issues.

2 participants