Skip to content

Conversation

pythongosssss
Copy link
Collaborator

image

This updates the logging from using a MemoryHandler to overriding stdout/stderr in order to obtain all outputs, including progress bars. (Previously done here #4664)

Adds two new endpoints for the frontend
GET /internal/logs/raw - returns an array of the last 300 raw stdout/stderr entries and their timestamps, and the size of the terminal (required for accurate rendering)
POST /internal/logs/subscribe - Body: clientId: the socket id, enabled: if logs are being subscribed to send via websocket in a new event logs.

The format of /internal/logs has slightly changed as it is no longer formatted via logging but just the outputs.

The logs event contains any entries since last flush and the terminal size if it has changed.
Events are only sent via the websocket when a client is subscribed to reduce unnecessary traffic.

@pythongosssss pythongosssss changed the title Terminal live output Live terminal output Oct 28, 2024
Copy link
Contributor

@huchenlei huchenlei left a comment

Choose a reason for hiding this comment

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

LGTM! @comfyanonymous PTAL

@huchenlei huchenlei added the Good PR This PR looks good to go, it needs comfy's final review. label Oct 30, 2024
@pythongosssss pythongosssss marked this pull request as ready for review October 30, 2024 19:57
@comfyanonymous
Copy link
Owner

There's an issue with this on Linux where if I add some prints in the code I only see them after I ctrl-c comfyui.

@pythongosssss
Copy link
Collaborator Author

I'm not able to reproduce using WSL2, are you getting no log output at all?

@comfyanonymous
Copy link
Owner

I add a print here for example: https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/ops.py#L67

# else logs just get full of progress messages
if isinstance(data, str) and data.startswith("\r") and not logs[-1]["m"].endswith("\n"):
logs.pop()
logs.append(entry)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems here the handling of progress messages is altering original terminal behavior.

@huchenlei
Copy link
Contributor

@huchenlei
Copy link
Contributor

I add a print here for example: https://github.com/comfyanonymous/ComfyUI/blob/master/comfy/ops.py#L67

Context:

During the debug session, we observed if we have print statement printing stuffs while the progress bar is being actively updated, some logs are not properly output. They are flushed out only when pressing Ctrl+C.

@pythongosssss
Copy link
Collaborator Author

After a bunch of investigating, the fix here was to set the line_buffering to match the underlying stream

@comfyanonymous comfyanonymous merged commit 6ee066a into comfyanonymous:master Nov 9, 2024
5 checks passed
@pythongosssss pythongosssss deleted the terminal-live-output branch November 9, 2024 12:27
Chaoses-Ib added a commit to Chaoses-Ib/ComfyScript that referenced this pull request Nov 20, 2024
Using Jupyter Notebook + real mode / standalone virtual mode together is broken due to a recent change in ComfyUI. This commit works around it.

comfyanonymous/ComfyUI#5396
ipython/ipykernel#786
tiangles pushed a commit to diffus-me/ComfyUI that referenced this pull request Nov 29, 2024
* Add /logs/raw and /logs/subscribe for getting logs on frontend
Hijacks stderr/stdout to send all output data to the client on flush

* Use existing send sync method

* Fix get_logs should return string

* Fix bug

* pass no server

* fix tests

* Fix output flush on linux
@juntaosun
Copy link

juntaosun commented Sep 30, 2025

@pythongosssss

Hello, when I call POST /internal/logs/subscribe using the ComfyUI API, the server denies access and I get a cross-origin error.

has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

However, I have added the following startup parameters:

--enable-cors-header

❌ /internal/logs/subscribe POST failed!

    const payload = {
                enabled: true, 
                clientId: this.clientId, // clientId
            };

            // POST
            const response = await fetch(`http://127.0.0.1:8188/internal/logs/subscribe`, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json',
                },
                body: JSON.stringify(payload),
            });
image

This means the startup parameters are valid, but /internal/logs/subscribe is not working.
Can you fix this?

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

Labels

Good PR This PR looks good to go, it needs comfy's final review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants