mirror of
https://github.com/Comfy-Org/ComfyUI-Manager.git
synced 2025-12-16 18:02:58 +08:00
fix: add functionality to hook the logs generated by the logging module.
- Fix the issue where messages generated by the logging module are not being saved to a file and import failures are not being recognized.
This commit is contained in:
parent
de89992257
commit
9bd9084381
@ -23,7 +23,7 @@ sys.path.append(glob_path)
|
|||||||
import cm_global
|
import cm_global
|
||||||
from manager_util import *
|
from manager_util import *
|
||||||
|
|
||||||
version = [2, 44, 1]
|
version = [2, 44, 2]
|
||||||
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 '')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import locale
|
|||||||
import platform
|
import platform
|
||||||
import json
|
import json
|
||||||
import ast
|
import ast
|
||||||
|
import logging
|
||||||
|
|
||||||
glob_path = os.path.join(os.path.dirname(__file__), "glob")
|
glob_path = os.path.join(os.path.dirname(__file__), "glob")
|
||||||
sys.path.append(glob_path)
|
sys.path.append(glob_path)
|
||||||
@ -202,6 +202,7 @@ try:
|
|||||||
|
|
||||||
is_start_mode = True
|
is_start_mode = True
|
||||||
|
|
||||||
|
|
||||||
class ComfyUIManagerLogger:
|
class ComfyUIManagerLogger:
|
||||||
def __init__(self, is_stdout):
|
def __init__(self, is_stdout):
|
||||||
self.is_stdout = is_stdout
|
self.is_stdout = is_stdout
|
||||||
@ -250,7 +251,7 @@ try:
|
|||||||
else:
|
else:
|
||||||
self.sync_write(message)
|
self.sync_write(message)
|
||||||
|
|
||||||
def sync_write(self, message):
|
def sync_write(self, message, file_only=False):
|
||||||
with log_lock:
|
with log_lock:
|
||||||
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')[:-3]
|
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')[:-3]
|
||||||
if self.last_char != '\n':
|
if self.last_char != '\n':
|
||||||
@ -260,15 +261,16 @@ try:
|
|||||||
log_file.flush()
|
log_file.flush()
|
||||||
self.last_char = message if message == '' else message[-1]
|
self.last_char = message if message == '' else message[-1]
|
||||||
|
|
||||||
with std_log_lock:
|
if not file_only:
|
||||||
if self.is_stdout:
|
with std_log_lock:
|
||||||
write_stdout(message)
|
if self.is_stdout:
|
||||||
original_stdout.flush()
|
write_stdout(message)
|
||||||
terminal_hook.write_stderr(message)
|
original_stdout.flush()
|
||||||
else:
|
terminal_hook.write_stderr(message)
|
||||||
write_stderr(message)
|
else:
|
||||||
original_stderr.flush()
|
write_stderr(message)
|
||||||
terminal_hook.write_stdout(message)
|
original_stderr.flush()
|
||||||
|
terminal_hook.write_stdout(message)
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
log_file.flush()
|
log_file.flush()
|
||||||
@ -305,6 +307,28 @@ try:
|
|||||||
else:
|
else:
|
||||||
sys.stdout.close_log = lambda: None
|
sys.stdout.close_log = lambda: None
|
||||||
|
|
||||||
|
|
||||||
|
class LoggingHandler(logging.Handler):
|
||||||
|
def emit(self, record):
|
||||||
|
global is_start_mode
|
||||||
|
|
||||||
|
message = record.getMessage()
|
||||||
|
|
||||||
|
if is_start_mode:
|
||||||
|
match = re.search(pat_import_fail, message)
|
||||||
|
if match:
|
||||||
|
import_failed_extensions.add(match.group(1))
|
||||||
|
|
||||||
|
if 'Starting server' in message:
|
||||||
|
is_start_mode = False
|
||||||
|
|
||||||
|
if enable_file_logging:
|
||||||
|
sys.stderr.sync_write(message+'\n', file_only=True)
|
||||||
|
|
||||||
|
|
||||||
|
logging.getLogger().addHandler(LoggingHandler())
|
||||||
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[ComfyUI-Manager] Logging failed: {e}")
|
print(f"[ComfyUI-Manager] Logging failed: {e}")
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "comfyui-manager"
|
name = "comfyui-manager"
|
||||||
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
|
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
|
||||||
version = "2.44.1"
|
version = "2.44.2"
|
||||||
license = "LICENSE"
|
license = "LICENSE"
|
||||||
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]
|
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user