Get logs endpoint & system_stats additions#4664
Get logs endpoint & system_stats additions#4664pythongosssss wants to merge 4 commits intoComfy-Org:masterfrom
Conversation
| # Intercept logs for error reporting | ||
| import sys | ||
| from app.log_interceptor import LogInterceptor | ||
| sys.stdout = LogInterceptor(sys.stdout) |
There was a problem hiding this comment.
All the logging in core comfy uses the logging python module so is this really the best way of doing this?
There was a problem hiding this comment.
All the logging in core comfy uses the logging python module so is this really the best way of doing this?
We also want to intercept all stdout from custom nodes which we don't have control over. Custom nodes can just call print for console message. Currently ComfyUI-Manager is doing the same stdout object hijack to save output log file.
|
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 |
|
Updated per feedback |
|
@comfyanonymous Gentle ping on the review |
|
Nice to see another |
|
|
||
| # Setup default global logger | ||
| logger = logging.getLogger() | ||
| logger.setLevel(logging.INFO) |
Some additions for better error reporting
Adds new
/internal/logsendpoint for getting the last 300 log entriesUpdates
/system_statsto includecomfyui_version(if in a git repo),pytorch_versionandargvfor the launch args.Using
pygit2as that is included with the Windows releases, falling back to calling git manually.Replaces output streams with
LogInterceptorwhich I've tested with ComfyUI Managers output hooks, not sure if other nodes do anything with these streams that may cause/have issues.