Skip to content

Add colored logs#14036

Merged
alexisrolland merged 6 commits into
masterfrom
colored-logs
May 25, 2026
Merged

Add colored logs#14036
alexisrolland merged 6 commits into
masterfrom
colored-logs

Conversation

@Talmaj

@Talmaj Talmaj commented May 21, 2026

Copy link
Copy Markdown
Contributor

Sometimes it's very hard to read the logs efficiently. This PR adds optional flag when starting comfyUI python main.py --color-logs

This colors all the infos green, warnings orange and errors red. See the image:
Screenshot 2026-05-21 at 21 59 04

I would personally set this as a default option.

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8da3c6ca-2d5f-4ca5-98f7-283d50240780

📥 Commits

Reviewing files that changed from the base of the PR and between 85816fa and d9ae39b.

📒 Files selected for processing (1)
  • main.py

📝 Walkthrough

Walkthrough

This PR adds ANSI color formatting to log output. app/logger.py introduces a ColoredFormatter that prepends bold, color-coded [LEVEL] prefixes for WARNING and above and optionally colorizes message bodies when a record includes a color attribute. setup_logger is updated to use this formatter for stream and stdout handlers. main.py tags prompt execution timing logs with extra={'color': 'green'} so those messages render in green.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add colored logs' directly and concisely describes the main change in the PR—introducing colored log output formatting.
Description check ✅ Passed The description explains the motivation for colored logs, mentions the color scheme (green for info, orange for warnings, red for errors), and provides a screenshot demonstrating the feature.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@alexisrolland

Copy link
Copy Markdown
Member

@Talmaj thank you for this PR, we discussed this with @comfyanonymous could you please remove the flag and make this the default behavior. Thanks!

@jovan2009

jovan2009 commented May 22, 2026

Copy link
Copy Markdown

@Talmaj Thanks a lot for this feature. I always wanted to make a feature request about something like this but I feared is too frivolous.

Since we are on this subject I think maybe here is the place to make a related feature request:
In many occasions I let a video generation to run and I go away from the computer but in a place where I can still see the computer screen. I maximize the console and I glance from time to time to get an idea if it's finished or not. Because I'm short sighted I can't always tell if the execution is finished and I always wanted a bold green message when it comes to "Prompt executed in ...". Somewhat like you get when you compile something into a wheel and you get at the end a green message that the wheel was built successfully.
TLDR: What I'm asking is for the entire message about prompt being done to be bold and green, not only the [INFO] tag.

@Talmaj

Talmaj commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

@jovan2009 I am ok to do add this, but we'd need a confirmation from @comfyanonymous first.
I think already this current change should help you a lot.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/logger.py (1)

72-72: ⚡ Quick win

Consider terminal capability detection for robustness.

The colored logs are now enabled by default, which works well on modern terminals. However, ANSI escape codes will appear as literal text on terminals that don't support them (rare but possible) or when output is redirected to files.

For enhanced robustness, consider checking sys.stdout.isatty() and/or sys.stderr.isatty() before defaulting to colored output. This is not critical since users can disable via --no-color-logs, but it would provide a better out-of-the-box experience in edge cases.

🎨 Optional enhancement to detect terminal capability
-def setup_logger(log_level: str = 'INFO', capacity: int = 300, use_stdout: bool = False, color_logs: bool = True):
+def setup_logger(log_level: str = 'INFO', capacity: int = 300, use_stdout: bool = False, color_logs: bool = True):
     global logs
     if logs:
         return
@@ -86,7 +86,10 @@
     logger = logging.getLogger()
     logger.setLevel(log_level)
 
-    formatter = ColoredFormatter("%(message)s") if color_logs else logging.Formatter("%(message)s")
+    # Auto-detect if terminal supports colors when color_logs is True
+    supports_color = color_logs and (sys.stderr.isatty() or (use_stdout and sys.stdout.isatty()))
+    
+    formatter = ColoredFormatter("%(message)s") if supports_color else logging.Formatter("%(message)s")

Also applies to: 89-89

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/logger.py` at line 72, The setup_logger function currently enables
color_logs by default; change its behavior to detect terminal capability
instead: make color_logs optional (e.g., None) and inside setup_logger decide
its effective value using sys.stdout.isatty() or sys.stderr.isatty() (choose
stdout when use_stdout is True, otherwise stderr), so colors are only enabled
when the chosen stream is a TTY; ensure explicit True/False passed by callers
still overrides detection and keep use_stdout, color_logs and setup_logger as
the referenced symbols to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@app/logger.py`:
- Line 72: The setup_logger function currently enables color_logs by default;
change its behavior to detect terminal capability instead: make color_logs
optional (e.g., None) and inside setup_logger decide its effective value using
sys.stdout.isatty() or sys.stderr.isatty() (choose stdout when use_stdout is
True, otherwise stderr), so colors are only enabled when the chosen stream is a
TTY; ensure explicit True/False passed by callers still overrides detection and
keep use_stdout, color_logs and setup_logger as the referenced symbols to locate
the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c4a84e7f-a0ab-4e7c-b9c1-520877778ec6

📥 Commits

Reviewing files that changed from the base of the PR and between 2e2502a and 536dc26.

📒 Files selected for processing (2)
  • app/logger.py
  • comfy/cli_args.py
@alexisrolland

Copy link
Copy Markdown
Member

@jovan2009 I am ok to do add this, but we'd need a confirmation from @comfyanonymous first. I think already this current change should help you a lot.

I discussed with @comfyanonymous and he said he approves this additional change

TLDR: What I'm asking is for the entire message about prompt being done to be bold and green, not only the [INFO] tag.

@jovan2009

Copy link
Copy Markdown

@jovan2009 I am ok to do add this, but we'd need a confirmation from @comfyanonymous first. I think already this current change should help you a lot.

I discussed with @comfyanonymous and he said he approves this additional change

TLDR: What I'm asking is for the entire message about prompt being done to be bold and green, not only the [INFO] tag.

You guys made my day. I'm looking forward for this PR to be merged. Thanks a lot!

@Talmaj

Talmaj commented May 23, 2026

Copy link
Copy Markdown
Contributor Author

@alexisrolland @jovan2009 done. I've added coloring of text as a new feature. One can do:
logging.info("message", extra={"color": "green"})

This will color only the "message" part, not the logging level part.
That means that [INFO], [WARNING], [ERROR] remain the same, and use pre-defined fixed colors.

@alexisrolland

Copy link
Copy Markdown
Member

Thanks @Talmaj could you also please remove the feature flag?

@Talmaj Talmaj changed the title Add --color-logs option May 24, 2026
@Talmaj

Talmaj commented May 24, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
main.py (1)

347-347: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Verify that green-only coloring meets the "bold and green" requirement.

The reviewer jovan2009 requested that the completion message be "bold and green", but the current implementation only applies green color via extra={'color': 'green'}. The ColoredFormatter applies bold only to level tags for WARNING and above (line 34 in app/logger.py), so these INFO-level messages will be green but not bold.

If bold text is required for the message body (not just the [INFO] tag), you'll need to either:

  1. Add a bold attribute to the extra dict and handle it in ColoredFormatter.format(), or
  2. Include ANSI bold codes directly in the formatted message string

Also applies to: 349-349

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@main.py` at line 347, The INFO-level completion log uses extra={'color':
'green'} which only colors the tag; to make the message body "bold and green"
update the logging call(s) (the logging.info at the prompt completion lines) to
either include extra={'color': 'green', 'bold': True} and extend
ColoredFormatter.format() to respect a 'bold' key when applying styles, or else
embed ANSI bold sequences directly into the formatted message string; modify
ColoredFormatter.format() to read the new 'bold' attribute (or the embedded
codes will already render) so the message body is rendered bold and green.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@main.py`:
- Line 347: The INFO-level completion log uses extra={'color': 'green'} which
only colors the tag; to make the message body "bold and green" update the
logging call(s) (the logging.info at the prompt completion lines) to either
include extra={'color': 'green', 'bold': True} and extend
ColoredFormatter.format() to respect a 'bold' key when applying styles, or else
embed ANSI bold sequences directly into the formatted message string; modify
ColoredFormatter.format() to read the new 'bold' attribute (or the embedded
codes will already render) so the message body is rendered bold and green.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3cbf6dd7-013e-4bec-b1a7-1f79f32018f3

📥 Commits

Reviewing files that changed from the base of the PR and between 3a5afc1 and 85816fa.

📒 Files selected for processing (2)
  • app/logger.py
  • main.py
@alexisrolland alexisrolland merged commit 63bcaec into master May 25, 2026
21 checks passed
simonri pushed a commit to simonri/ComfyUI-flash-attention-3 that referenced this pull request May 26, 2026
@alexisrolland alexisrolland deleted the colored-logs branch June 9, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants