Skip to content

Commit

Permalink
Remove problematic printout and make log windows update if a new log …
Browse files Browse the repository at this point in the history
…is added
  • Loading branch information
andrewharp committed Aug 4, 2024
1 parent 7e88939 commit 7c31750
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
9 changes: 5 additions & 4 deletions easy_nodes/log_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import re
import traceback
from typing import Dict, List, Tuple

import folder_paths
Expand Down Expand Up @@ -186,7 +187,7 @@ async def stream_content(response, content_generator):
async def send_footer(response):
await response.write(b"</pre></body></html>")
response.force_close()


@routes.get("/easy_nodes/show_log")
async def show_log(request):
Expand Down Expand Up @@ -225,8 +226,8 @@ async def show_log(request):

await response.write(b"=====================================\n\nEnd of node logs.")
await send_footer(response)
except Exception as _:
pass
except Exception as e:
logging.error(f"Error in show_log: {str(e)} stack trace: {traceback.format_exc()}")

return response

Expand Down Expand Up @@ -254,7 +255,7 @@ def add_log_buffer(node_id: str, node_class: str, prompt_id: str, input_desc: st
log_list.append((input_desc, buffer_wrapper))

nodes_with_logs = [key for key in _buffers.keys()]
PromptServer.instance.send_sync("logs_updated", {"nodes_with_logs": nodes_with_logs}, None)
PromptServer.instance.send_sync("logs_updated", {"nodes_with_logs": nodes_with_logs, "prompt_id": prompt_id}, None)


@routes.get("/easy_nodes/verify_image")
Expand Down
16 changes: 15 additions & 1 deletion easy_nodes/web/easy_nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ class FloatingLogWindow {
});
}

resetStream() {
this.content.innerHTML = ''; // Clear previous content
this.content.scrollTop = 0; // Reset scroll position
this.streamLog();
}

show(x, y, nodeId) {
if (!this.window) this.create();

Expand All @@ -279,7 +285,7 @@ class FloatingLogWindow {
}

this.window.style.display = 'flex';

if (this.currentNodeId !== nodeId) {
this.currentNodeId = nodeId;
this.content.innerHTML = ''; // Clear previous content
Expand Down Expand Up @@ -787,10 +793,18 @@ api.addEventListener("execution_error", function(e) {

api.addEventListener('logs_updated', ({ detail, }) => {
let nodesWithLogs = detail.nodes_with_logs;
let prompt_id = detail.prompt_id;

console.log("Nodes with logs: ", nodesWithLogs);

app.graph._nodes.forEach((node) => {
let strNodeId = "" + node.id;
node.has_log = nodesWithLogs.includes(strNodeId);
});

// If the floating log window is showing logs for a node that has a new log, refresh it:
console.log("Current node id: ", floatingLogWindow.currentNodeId);
if (floatingLogWindow.currentNodeId && nodesWithLogs.includes(floatingLogWindow.currentNodeId + "")) {
floatingLogWindow.resetStream();
}
}, false);

0 comments on commit 7c31750

Please sign in to comment.