ComfyUI
ComfyUI copied to clipboard
Get logs endpoint & system_stats additions
Some additions for better error reporting
Adds new /internal/logs endpoint for getting the last 300 log entries
Updates /system_stats to include comfyui_version (if in a git repo), pytorch_version and argv for the launch args.
Using pygit2 as that is included with the Windows releases, falling back to calling git manually.
Replaces output streams with LogInterceptor which I've tested with ComfyUI Managers output hooks, not sure if other nodes do anything with these streams that may cause/have issues.
From claude:
from logging.handlers import MemoryHandler
from collections import deque
def setup_memory_logger(logger_name='root', level=logging.INFO, capacity=300):
# Get the root logger
logger = logging.getLogger(logger_name)
logger.setLevel(level)
# Create a memory handler with a deque as its buffer
memory_handler = MemoryHandler(capacity, flushLevel=logging.ERROR)
memory_handler.buffer = deque(maxlen=capacity)
# Create a formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
memory_handler.setFormatter(formatter)
# Add the memory handler to the logger
logger.addHandler(memory_handler)
def get_log_contents():
return '\n'.join(memory_handler.buffer)
return logger, get_log_contents
# Usage example
if __name__ == "__main__":
logger, get_logs = setup_memory_logger()
# Log some messages
for i in range(350):
logger.info(f"Log message {i}")
# Simulate an error
try:
1 / 0
except ZeroDivisionError:
logger.exception("Caught an exception")
# Get the last 300 log messages
log_contents = get_logs()
print("Last 300 log messages:")
print(log_contents)
So there is a MemoryHandler that can be used to cache log messages. It's less hacky than the stdout/stderr hijack.
Offline discussion final decision: go with logging handler and see if the log satisfied our need in error reports.
Downside of this is that it doesn't capture millions of custom nodes that does print statement, but we can first start in this way and see whether it will end up missing context for user issue reporting https://sourcegraph.com/search?q=repo:ComfyUI+%22++print%28%22&patternType=keyword&sm=0
Updated per feedback
@comfyanonymous Gentle ping on the review
Nice to see another /internal route :)