mirror of
https://git.datalinker.icu/ltdrdata/ComfyUI-Manager
synced 2025-12-09 06:04:31 +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
|
||||
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 '')
|
||||
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import locale
|
||||
import platform
|
||||
import json
|
||||
import ast
|
||||
|
||||
import logging
|
||||
|
||||
glob_path = os.path.join(os.path.dirname(__file__), "glob")
|
||||
sys.path.append(glob_path)
|
||||
@ -202,6 +202,7 @@ try:
|
||||
|
||||
is_start_mode = True
|
||||
|
||||
|
||||
class ComfyUIManagerLogger:
|
||||
def __init__(self, is_stdout):
|
||||
self.is_stdout = is_stdout
|
||||
@ -250,7 +251,7 @@ try:
|
||||
else:
|
||||
self.sync_write(message)
|
||||
|
||||
def sync_write(self, message):
|
||||
def sync_write(self, message, file_only=False):
|
||||
with log_lock:
|
||||
timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')[:-3]
|
||||
if self.last_char != '\n':
|
||||
@ -260,15 +261,16 @@ try:
|
||||
log_file.flush()
|
||||
self.last_char = message if message == '' else message[-1]
|
||||
|
||||
with std_log_lock:
|
||||
if self.is_stdout:
|
||||
write_stdout(message)
|
||||
original_stdout.flush()
|
||||
terminal_hook.write_stderr(message)
|
||||
else:
|
||||
write_stderr(message)
|
||||
original_stderr.flush()
|
||||
terminal_hook.write_stdout(message)
|
||||
if not file_only:
|
||||
with std_log_lock:
|
||||
if self.is_stdout:
|
||||
write_stdout(message)
|
||||
original_stdout.flush()
|
||||
terminal_hook.write_stderr(message)
|
||||
else:
|
||||
write_stderr(message)
|
||||
original_stderr.flush()
|
||||
terminal_hook.write_stdout(message)
|
||||
|
||||
def flush(self):
|
||||
log_file.flush()
|
||||
@ -305,6 +307,28 @@ try:
|
||||
else:
|
||||
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:
|
||||
print(f"[ComfyUI-Manager] Logging failed: {e}")
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
[project]
|
||||
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."
|
||||
version = "2.44.1"
|
||||
version = "2.44.2"
|
||||
license = "LICENSE"
|
||||
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user