mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-16 18:02:58 +08:00
feat: optional file_logging
fix: robust file_logging https://github.com/ltdrdata/ComfyUI-Manager/issues/375
This commit is contained in:
parent
a7c78ffa29
commit
813a1ce6b0
@ -255,8 +255,12 @@ NODE_CLASS_MAPPINGS.update({
|
|||||||
|
|
||||||
|
|
||||||
## Additional Feature
|
## Additional Feature
|
||||||
|
* Logging to file feature
|
||||||
|
* This feature is enabled by default and can be disabled by setting `file_logging = False` in the `config.ini`.
|
||||||
|
|
||||||
* Fix node(recreate): When right-clicking on a node and selecting `Fix node (recreate)`, you can recreate the node. The widget's values are reset, while the connections maintain those with the same names.
|
* Fix node(recreate): When right-clicking on a node and selecting `Fix node (recreate)`, you can recreate the node. The widget's values are reset, while the connections maintain those with the same names.
|
||||||
* It is used to correct errors in nodes of old workflows created before, which are incompatible with the version changes of custom nodes.
|
* It is used to correct errors in nodes of old workflows created before, which are incompatible with the version changes of custom nodes.
|
||||||
|
|
||||||
* Double-Click Node Title: You can set the double click behavior of nodes in the ComfyUI-Manager menu.
|
* Double-Click Node Title: You can set the double click behavior of nodes in the ComfyUI-Manager menu.
|
||||||
* `Copy All Connections`, `Copy Input Connections`: Double-clicking a node copies the connections of the nearest node.
|
* `Copy All Connections`, `Copy Input Connections`: Double-clicking a node copies the connections of the nearest node.
|
||||||
* This action targets the nearest node within a straight-line distance of 1000 pixels from the center of the node.
|
* This action targets the nearest node within a straight-line distance of 1000 pixels from the center of the node.
|
||||||
|
|||||||
@ -29,7 +29,7 @@ except:
|
|||||||
print(f"[WARN] ComfyUI-Manager: Your ComfyUI version is outdated. Please update to the latest version.")
|
print(f"[WARN] ComfyUI-Manager: Your ComfyUI version is outdated. Please update to the latest version.")
|
||||||
|
|
||||||
|
|
||||||
version = [2, 5, 2]
|
version = [2, 6]
|
||||||
version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '')
|
version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '')
|
||||||
print(f"### Loading: ComfyUI-Manager ({version_str})")
|
print(f"### Loading: ComfyUI-Manager ({version_str})")
|
||||||
|
|
||||||
@ -173,6 +173,7 @@ def write_config():
|
|||||||
'channel_url': get_config()['channel_url'],
|
'channel_url': get_config()['channel_url'],
|
||||||
'share_option': get_config()['share_option'],
|
'share_option': get_config()['share_option'],
|
||||||
'bypass_ssl': get_config()['bypass_ssl'],
|
'bypass_ssl': get_config()['bypass_ssl'],
|
||||||
|
"file_logging": get_config()['file_logging'],
|
||||||
'default_ui': get_config()['default_ui'],
|
'default_ui': get_config()['default_ui'],
|
||||||
'component_policy': get_config()['component_policy'],
|
'component_policy': get_config()['component_policy'],
|
||||||
'double_click_policy': get_config()['double_click_policy'],
|
'double_click_policy': get_config()['double_click_policy'],
|
||||||
@ -195,10 +196,11 @@ def read_config():
|
|||||||
'channel_url': default_conf['channel_url'] if 'channel_url' in default_conf else 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main',
|
'channel_url': default_conf['channel_url'] if 'channel_url' in default_conf else 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main',
|
||||||
'share_option': default_conf['share_option'] if 'share_option' in default_conf else 'all',
|
'share_option': default_conf['share_option'] if 'share_option' in default_conf else 'all',
|
||||||
'bypass_ssl': default_conf['bypass_ssl'] if 'bypass_ssl' in default_conf else False,
|
'bypass_ssl': default_conf['bypass_ssl'] if 'bypass_ssl' in default_conf else False,
|
||||||
|
'file_logging': default_conf['file_logging'] if 'file_logging' in default_conf else True,
|
||||||
'default_ui': default_conf['default_ui'] if 'default_ui' in default_conf else 'none',
|
'default_ui': default_conf['default_ui'] if 'default_ui' in default_conf else 'none',
|
||||||
'component_policy': default_conf['component_policy'] if 'component_policy' in default_conf else 'workflow',
|
'component_policy': default_conf['component_policy'] if 'component_policy' in default_conf else 'workflow',
|
||||||
'double_click_policy': default_conf['double_click_policy'] if 'double_click_policy' in default_conf else 'copy-all',
|
'double_click_policy': default_conf['double_click_policy'] if 'double_click_policy' in default_conf else 'copy-all',
|
||||||
"windows_selector_event_loop_policy": default_conf['windows_selector_event_loop_policy'] if 'windows_selector_event_loop_policy' in default_conf else False,
|
'windows_selector_event_loop_policy': default_conf['windows_selector_event_loop_policy'] if 'windows_selector_event_loop_policy' in default_conf else False,
|
||||||
}
|
}
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
@ -209,6 +211,7 @@ def read_config():
|
|||||||
'channel_url': 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main',
|
'channel_url': 'https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main',
|
||||||
'share_option': 'all',
|
'share_option': 'all',
|
||||||
'bypass_ssl': False,
|
'bypass_ssl': False,
|
||||||
|
'file_logging': True,
|
||||||
'default_ui': 'none',
|
'default_ui': 'none',
|
||||||
'component_policy': 'workflow',
|
'component_policy': 'workflow',
|
||||||
'double_click_policy': 'copy-all',
|
'double_click_policy': 'copy-all',
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import cm_global
|
|||||||
message_collapses = []
|
message_collapses = []
|
||||||
import_failed_extensions = set()
|
import_failed_extensions = set()
|
||||||
cm_global.variables['cm.on_revision_detected_handler'] = []
|
cm_global.variables['cm.on_revision_detected_handler'] = []
|
||||||
|
enable_file_logging = True
|
||||||
|
|
||||||
|
|
||||||
def register_message_collapse(f):
|
def register_message_collapse(f):
|
||||||
@ -30,6 +31,24 @@ def is_import_failed_extension(name):
|
|||||||
return name in import_failed_extensions
|
return name in import_failed_extensions
|
||||||
|
|
||||||
|
|
||||||
|
def check_file_logging():
|
||||||
|
global enable_file_logging
|
||||||
|
try:
|
||||||
|
import configparser
|
||||||
|
config_path = os.path.join(os.path.dirname(__file__), "config.ini")
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(config_path)
|
||||||
|
default_conf = config['default']
|
||||||
|
|
||||||
|
if 'file_logging' in default_conf and default_conf['file_logging'].lower() == 'false':
|
||||||
|
enable_file_logging = False
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
check_file_logging()
|
||||||
|
|
||||||
|
|
||||||
sys.__comfyui_manager_register_message_collapse = register_message_collapse
|
sys.__comfyui_manager_register_message_collapse = register_message_collapse
|
||||||
sys.__comfyui_manager_is_import_failed_extension = is_import_failed_extension
|
sys.__comfyui_manager_is_import_failed_extension = is_import_failed_extension
|
||||||
cm_global.register_api('cm.register_message_collapse', register_message_collapse)
|
cm_global.register_api('cm.register_message_collapse', register_message_collapse)
|
||||||
@ -118,16 +137,34 @@ try:
|
|||||||
postfix = ""
|
postfix = ""
|
||||||
|
|
||||||
# Logger setup
|
# Logger setup
|
||||||
if os.path.exists(f"comfyui{postfix}.log"):
|
if enable_file_logging:
|
||||||
if os.path.exists(f"comfyui{postfix}.prev.log"):
|
if os.path.exists(f"comfyui{postfix}.log"):
|
||||||
if os.path.exists(f"comfyui{postfix}.prev2.log"):
|
if os.path.exists(f"comfyui{postfix}.prev.log"):
|
||||||
os.remove(f"comfyui{postfix}.prev2.log")
|
if os.path.exists(f"comfyui{postfix}.prev2.log"):
|
||||||
os.rename(f"comfyui{postfix}.prev.log", f"comfyui{postfix}.prev2.log")
|
os.remove(f"comfyui{postfix}.prev2.log")
|
||||||
os.rename(f"comfyui{postfix}.log", f"comfyui{postfix}.prev.log")
|
os.rename(f"comfyui{postfix}.prev.log", f"comfyui{postfix}.prev2.log")
|
||||||
|
os.rename(f"comfyui{postfix}.log", f"comfyui{postfix}.prev.log")
|
||||||
|
|
||||||
|
log_file = open(f"comfyui{postfix}.log", "w", encoding="utf-8", errors="ignore")
|
||||||
|
|
||||||
|
log_lock = threading.Lock()
|
||||||
|
|
||||||
original_stdout = sys.stdout
|
original_stdout = sys.stdout
|
||||||
original_stderr = sys.stderr
|
original_stderr = sys.stderr
|
||||||
|
|
||||||
|
if original_stdout.encoding.lower() == 'utf-8':
|
||||||
|
write_stdout = original_stdout.write
|
||||||
|
write_stderr = original_stderr.write
|
||||||
|
else:
|
||||||
|
def wrapper_stdout(msg):
|
||||||
|
original_stdout.write(msg.encode('utf-8').decode(original_stdout.encoding, errors="ignore"))
|
||||||
|
|
||||||
|
def wrapper_stderr(msg):
|
||||||
|
original_stderr.write(msg.encode('utf-8').decode(original_stderr.encoding, errors="ignore"))
|
||||||
|
|
||||||
|
write_stdout = wrapper_stdout
|
||||||
|
write_stderr = wrapper_stderr
|
||||||
|
|
||||||
pat_tqdm = r'\d+%.*\[(.*?)\]'
|
pat_tqdm = r'\d+%.*\[(.*?)\]'
|
||||||
pat_import_fail = r'seconds \(IMPORT FAILED\):'
|
pat_import_fail = r'seconds \(IMPORT FAILED\):'
|
||||||
pat_custom_node = r'[/\\]custom_nodes[/\\](.*)$'
|
pat_custom_node = r'[/\\]custom_nodes[/\\](.*)$'
|
||||||
@ -135,9 +172,6 @@ try:
|
|||||||
is_start_mode = True
|
is_start_mode = True
|
||||||
is_import_fail_mode = False
|
is_import_fail_mode = False
|
||||||
|
|
||||||
log_file = open(f"comfyui{postfix}.log", "w", encoding="utf-8", errors="ignore")
|
|
||||||
log_lock = threading.Lock()
|
|
||||||
|
|
||||||
class ComfyUIManagerLogger:
|
class ComfyUIManagerLogger:
|
||||||
def __init__(self, is_stdout):
|
def __init__(self, is_stdout):
|
||||||
self.is_stdout = is_stdout
|
self.is_stdout = is_stdout
|
||||||
@ -185,7 +219,7 @@ try:
|
|||||||
if '100%' in message:
|
if '100%' in message:
|
||||||
self.sync_write(message)
|
self.sync_write(message)
|
||||||
else:
|
else:
|
||||||
original_stderr.write(message)
|
write_stderr(message)
|
||||||
original_stderr.flush()
|
original_stderr.flush()
|
||||||
else:
|
else:
|
||||||
self.sync_write(message)
|
self.sync_write(message)
|
||||||
@ -204,11 +238,11 @@ try:
|
|||||||
|
|
||||||
with std_log_lock:
|
with std_log_lock:
|
||||||
if self.is_stdout:
|
if self.is_stdout:
|
||||||
original_stdout.write(message)
|
write_stdout(message)
|
||||||
original_stdout.flush()
|
original_stdout.flush()
|
||||||
terminal_hook.write_stderr(message)
|
terminal_hook.write_stderr(message)
|
||||||
else:
|
else:
|
||||||
original_stderr.write(message)
|
write_stderr(message)
|
||||||
original_stderr.flush()
|
original_stderr.flush()
|
||||||
terminal_hook.write_stdout(message)
|
terminal_hook.write_stdout(message)
|
||||||
|
|
||||||
@ -237,11 +271,16 @@ try:
|
|||||||
sys.stderr = original_stderr
|
sys.stderr = original_stderr
|
||||||
sys.stdout = original_stdout
|
sys.stdout = original_stdout
|
||||||
log_file.close()
|
log_file.close()
|
||||||
|
|
||||||
sys.stdout = ComfyUIManagerLogger(True)
|
|
||||||
sys.stderr = ComfyUIManagerLogger(False)
|
|
||||||
|
|
||||||
atexit.register(close_log)
|
|
||||||
|
if enable_file_logging:
|
||||||
|
sys.stdout = ComfyUIManagerLogger(True)
|
||||||
|
sys.stderr = ComfyUIManagerLogger(False)
|
||||||
|
|
||||||
|
atexit.register(close_log)
|
||||||
|
else:
|
||||||
|
sys.stdout.close_log = lambda: None
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[ComfyUI-Manager] Logging failed: {e}")
|
print(f"[ComfyUI-Manager] Logging failed: {e}")
|
||||||
|
|
||||||
@ -250,7 +289,11 @@ print("** ComfyUI startup time:", datetime.datetime.now())
|
|||||||
print("** Platform:", platform.system())
|
print("** Platform:", platform.system())
|
||||||
print("** Python version:", sys.version)
|
print("** Python version:", sys.version)
|
||||||
print("** Python executable:", sys.executable)
|
print("** Python executable:", sys.executable)
|
||||||
print("** Log path:", os.path.abspath('comfyui.log'))
|
|
||||||
|
if enable_file_logging:
|
||||||
|
print("** Log path:", os.path.abspath('comfyui.log'))
|
||||||
|
else:
|
||||||
|
print("** Log path: file logging is disabled")
|
||||||
|
|
||||||
|
|
||||||
def check_bypass_ssl():
|
def check_bypass_ssl():
|
||||||
@ -461,7 +504,6 @@ del pip_list
|
|||||||
def check_windows_event_loop_policy():
|
def check_windows_event_loop_policy():
|
||||||
try:
|
try:
|
||||||
import configparser
|
import configparser
|
||||||
import ssl
|
|
||||||
config_path = os.path.join(os.path.dirname(__file__), "config.ini")
|
config_path = os.path.join(os.path.dirname(__file__), "config.ini")
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(config_path)
|
config.read(config_path)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user