diff --git a/nodes/error_log.py b/nodes/error_log.py index a8b94ec..88824f2 100644 --- a/nodes/error_log.py +++ b/nodes/error_log.py @@ -1,5 +1,4 @@ import os -import glob class ErrorLogNode: @classmethod @@ -11,31 +10,25 @@ class ErrorLogNode: CATEGORY = "🌙DW" def get_error_log(self): - possible_log_paths = [ - os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "comfyui.log"), - os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "logs", "comfyui.log"), - os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "*.log"), - ] + base_dir = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) + log_dir = os.path.join(base_dir, "..", "..", "comfyui") + log_path = os.path.join(log_dir, "comfyui.log") - log_content = "未找到日志文件。搜索的位置:\n" - - for path in possible_log_paths: - log_content += f"- {path}\n" - if "*" in path: - matching_files = glob.glob(path) - if matching_files: - path = matching_files[0] # 使用找到的第一个日志文件 - - if os.path.exists(path): - try: - with open(path, "r", encoding="utf-8") as f: - file_content = f.read() - log_lines = file_content.splitlines()[-1000:] # 只返回最后的1000行 - return ("\n".join(log_lines),) - except Exception as e: - return (f"读取日志文件 '{path}' 时发生错误:{str(e)}",) + debug_info = f"Base Directory: {base_dir}\nLog Directory: {log_dir}\nLog Path: {log_path}\n" - return (log_content,) + if not os.path.exists(log_dir): + return (f"{debug_info}日志目录不存在。",) + + if not os.path.exists(log_path): + return (f"{debug_info}未找到日志文件。",) + + try: + with open(log_path, "r", encoding="utf-8") as f: + file_content = f.read() + log_lines = file_content.splitlines()[-1000:] # 只返回最后的1000行 + return ("\n".join(log_lines),) + except Exception as e: + return (f"{debug_info}读取日志文件 '{log_path}' 时发生错误:{str(e)}",) NODE_CLASS_MAPPINGS = { "ErrorLogNode": ErrorLogNode