mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-11-12 03:20:03 +08:00
Add route for getting output logs
This commit is contained in:
parent
6bbdcd28ae
commit
d86f59ced1
@ -2,6 +2,7 @@ from aiohttp import web
|
||||
from typing import Optional
|
||||
from folder_paths import models_dir, user_directory, output_directory
|
||||
from api_server.services.file_service import FileService
|
||||
from app.log_interceptor import logs
|
||||
|
||||
class InternalRoutes:
|
||||
'''
|
||||
@ -31,6 +32,15 @@ class InternalRoutes:
|
||||
except Exception as e:
|
||||
return web.json_response({"error": str(e)}, status=500)
|
||||
|
||||
@self.routes.get('/logs')
|
||||
async def get_logs(request):
|
||||
return web.json_response([
|
||||
{
|
||||
'timestamp': dt.isoformat(),
|
||||
'message': message
|
||||
}
|
||||
for dt, message in logs
|
||||
])
|
||||
|
||||
def get_app(self):
|
||||
if self._app is None:
|
||||
|
||||
21
app/log_interceptor.py
Normal file
21
app/log_interceptor.py
Normal file
@ -0,0 +1,21 @@
|
||||
import io
|
||||
import threading
|
||||
from datetime import datetime
|
||||
|
||||
from collections import deque
|
||||
logs = deque(maxlen=300)
|
||||
|
||||
class LogInterceptor(io.TextIOWrapper):
|
||||
def __init__(self, stream, *args, **kwargs):
|
||||
buffer = stream.buffer
|
||||
encoding = stream.encoding
|
||||
super().__init__(buffer, *args, **kwargs, encoding=encoding)
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def write(self, data):
|
||||
with self._lock:
|
||||
logs.append((datetime.now(), data))
|
||||
super().write(data)
|
||||
|
||||
def flush(self):
|
||||
super().flush()
|
||||
7
main.py
7
main.py
@ -1,13 +1,18 @@
|
||||
import comfy.options
|
||||
comfy.options.enable_args_parsing()
|
||||
|
||||
# Intercept logs for error reporting
|
||||
import sys
|
||||
from app.log_interceptor import LogInterceptor
|
||||
sys.stdout = LogInterceptor(sys.stdout)
|
||||
sys.stderr = LogInterceptor(sys.stderr)
|
||||
|
||||
import os
|
||||
import importlib.util
|
||||
import folder_paths
|
||||
import time
|
||||
from comfy.cli_args import args
|
||||
|
||||
|
||||
def execute_prestartup_script():
|
||||
def execute_script(script_path):
|
||||
module_name = os.path.splitext(script_path)[0]
|
||||
|
||||
@ -30,7 +30,7 @@ from app.user_manager import UserManager
|
||||
from model_filemanager import download_model, DownloadModelStatus
|
||||
from typing import Optional
|
||||
from api_server.routes.internal.internal_routes import InternalRoutes
|
||||
|
||||
import torch
|
||||
|
||||
class BinaryEventTypes:
|
||||
PREVIEW_IMAGE = 1
|
||||
@ -401,7 +401,7 @@ class PromptServer():
|
||||
return web.json_response(dt["__metadata__"])
|
||||
|
||||
@routes.get("/system_stats")
|
||||
async def get_queue(request):
|
||||
async def system_stats(request):
|
||||
device = comfy.model_management.get_torch_device()
|
||||
device_name = comfy.model_management.get_torch_device_name(device)
|
||||
vram_total, torch_vram_total = comfy.model_management.get_total_memory(device, torch_total_too=True)
|
||||
@ -410,7 +410,9 @@ class PromptServer():
|
||||
"system": {
|
||||
"os": os.name,
|
||||
"python_version": sys.version,
|
||||
"embedded_python": os.path.split(os.path.split(sys.executable)[0])[1] == "python_embeded"
|
||||
"pytorch_version": torch.version.__version__,
|
||||
"embedded_python": os.path.split(os.path.split(sys.executable)[0])[1] == "python_embeded",
|
||||
"argv": sys.argv
|
||||
},
|
||||
"devices": [
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user