From 20d2483c3a117da5c1327e1d076b1606a7a4b2af Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Wed, 28 May 2025 09:17:09 -0700 Subject: [PATCH 1/4] fix(logging): add safe encoding for Windows compatibility --- utils/logging_config.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/utils/logging_config.py b/utils/logging_config.py index ffa861e..5ccd5f6 100644 --- a/utils/logging_config.py +++ b/utils/logging_config.py @@ -88,13 +88,15 @@ class PromptManagerLogger: console_handler.setFormatter(formatter) self.logger.addHandler(console_handler) - # File handler with rotation + # File handler with rotation and safe encoding for Windows if self.config['file_logging']: log_file = self.log_dir / "prompt_manager.log" file_handler = logging.handlers.RotatingFileHandler( log_file, maxBytes=self.config['max_file_size'], - backupCount=self.config['backup_count'] + backupCount=self.config['backup_count'], + encoding='utf-8', + errors='replace' # Replace problematic characters instead of crashing ) file_handler.setFormatter(formatter) self.logger.addHandler(file_handler) @@ -196,7 +198,8 @@ class PromptManagerLogger: raise ValueError("Invalid log file path") try: - with open(log_file, 'r', encoding='utf-8') as f: + # Use UTF-8 encoding with error handling for Windows compatibility + with open(log_file, 'r', encoding='utf-8', errors='replace') as f: all_lines = f.readlines() return all_lines[-lines:] if lines > 0 else all_lines except Exception as e: @@ -213,8 +216,8 @@ class PromptManagerLogger: for log_file in self.log_dir.glob("prompt_manager.log*"): try: if log_file.name == 'prompt_manager.log': - # For main log file, just clear it - with open(log_file, 'w') as f: + # For main log file, just clear it with safe encoding + with open(log_file, 'w', encoding='utf-8', errors='replace') as f: f.write("") else: # For rotated files, delete them From 299e74ebd54d539ceac7de790fcc221fbaab290d Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Wed, 28 May 2025 09:17:21 -0700 Subject: [PATCH 2/4] style: Replace emojis with tags in diagnostics logs --- utils/diagnostics.py | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/utils/diagnostics.py b/utils/diagnostics.py index d3f2882..5620309 100644 --- a/utils/diagnostics.py +++ b/utils/diagnostics.py @@ -20,7 +20,7 @@ class GalleryDiagnostics: def run_full_diagnostic(self) -> Dict[str, Any]: """Run a complete diagnostic check.""" self.logger.info("\n" + "="*60) - self.logger.info("๐Ÿ” PROMPTMANAGER GALLERY DIAGNOSTICS") + self.logger.info("[DIAG] PROMPTMANAGER GALLERY DIAGNOSTICS") self.logger.info("="*60) results = { @@ -32,11 +32,11 @@ class GalleryDiagnostics: } self.logger.info("\n" + "="*60) - self.logger.info("๐Ÿ“‹ DIAGNOSTIC SUMMARY") + self.logger.info("[SUMMARY] DIAGNOSTIC SUMMARY") self.logger.info("="*60) for category, result in results.items(): - status = "โœ… PASS" if result['status'] == 'ok' else "โŒ FAIL" + status = "[PASS] PASS" if result['status'] == 'ok' else "[FAIL] FAIL" self.logger.info(f"{category.upper():<20} {status}") if result['status'] != 'ok': self.logger.warning(f" Issue: {result['message']}") @@ -46,7 +46,7 @@ class GalleryDiagnostics: def check_database(self) -> Dict[str, Any]: """Check database connection and structure.""" - self.logger.info("\n๐Ÿ—„๏ธ Checking Database...") + self.logger.info("\n[DB] Checking Database...") try: if not os.path.exists(self.db_path): @@ -61,7 +61,7 @@ class GalleryDiagnostics: # Check prompts table cursor = conn.execute("SELECT COUNT(*) as count FROM prompts") prompt_count = cursor.fetchone()['count'] - self.logger.info(f" ๐Ÿ“ Prompts in database: {prompt_count}") + self.logger.info(f" [NOTE] Prompts in database: {prompt_count}") # Check if generated_images table exists cursor = conn.execute(""" @@ -70,7 +70,7 @@ class GalleryDiagnostics: """) has_images_table = cursor.fetchone() is not None - self.logger.info(f" ๐Ÿ–ผ๏ธ Images table exists: {has_images_table}") + self.logger.info(f" [IMG] Images table exists: {has_images_table}") return { 'status': 'ok', @@ -86,7 +86,7 @@ class GalleryDiagnostics: def check_images_table(self) -> Dict[str, Any]: """Check the generated_images table specifically.""" - self.logger.info("\n๐Ÿ–ผ๏ธ Checking Images Table...") + self.logger.info("\n[IMG] Checking Images Table...") try: with sqlite3.connect(self.db_path) as conn: @@ -107,7 +107,7 @@ class GalleryDiagnostics: # Check image records cursor = conn.execute("SELECT COUNT(*) as count FROM generated_images") image_count = cursor.fetchone()['count'] - self.logger.info(f" ๐Ÿ“Š Images in database: {image_count}") + self.logger.info(f" [STATS] Images in database: {image_count}") # Get recent images cursor = conn.execute(""" @@ -119,7 +119,7 @@ class GalleryDiagnostics: """) recent_images = [dict(row) for row in cursor.fetchall()] - self.logger.info(f" ๐Ÿ•’ Recent images: {len(recent_images)}") + self.logger.info(f" [TIME] Recent images: {len(recent_images)}") for img in recent_images: self.logger.info(f" - {img['filename']} -> Prompt {img['prompt_id']}") @@ -137,12 +137,12 @@ class GalleryDiagnostics: def check_file_system(self) -> Dict[str, Any]: """Check file system and permissions.""" - self.logger.info("\n๐Ÿ“ Checking File System...") + self.logger.info("\n[DIR] Checking File System...") try: # Check current directory current_dir = os.getcwd() - self.logger.info(f" ๐Ÿ“‚ Current directory: {current_dir}") + self.logger.info(f" [FOLDER] Current directory: {current_dir}") # Check if we can write to current directory test_file = "test_write.tmp" @@ -154,7 +154,7 @@ class GalleryDiagnostics: except: can_write = False - self.logger.info(f" โœ๏ธ Can write to directory: {can_write}") + self.logger.info(f" [EDIT] Can write to directory: {can_write}") return { 'status': 'ok', @@ -170,7 +170,7 @@ class GalleryDiagnostics: def check_comfyui_output(self) -> Dict[str, Any]: """Check ComfyUI output directories.""" - self.logger.info("\n๐ŸŽจ Checking ComfyUI Output...") + self.logger.info("\n[STYLE] Checking ComfyUI Output...") output_dirs = [] @@ -188,16 +188,16 @@ class GalleryDiagnostics: abs_path = os.path.abspath(dir_path) if os.path.exists(abs_path): output_dirs.append(abs_path) - self.logger.info(f" ๐Ÿ“ Found output dir: {abs_path}") + self.logger.info(f" [DIR] Found output dir: {abs_path}") # Count images in this directory try: image_files = [] for ext in ['.png', '.jpg', '.jpeg', '.webp']: image_files.extend(Path(abs_path).rglob(f'*{ext}')) - self.logger.info(f" ๐Ÿ–ผ๏ธ Images found: {len(image_files)}") + self.logger.info(f" [IMG] Images found: {len(image_files)}") except Exception as e: - self.logger.error(f" โŒ Error scanning: {e}") + self.logger.error(f" [FAIL] Error scanning: {e}") # Try ComfyUI's folder_paths try: @@ -205,9 +205,9 @@ class GalleryDiagnostics: comfyui_output = folder_paths.get_output_directory() if comfyui_output and comfyui_output not in output_dirs: output_dirs.append(comfyui_output) - self.logger.info(f" ๐Ÿ“ ComfyUI output dir: {comfyui_output}") + self.logger.info(f" [DIR] ComfyUI output dir: {comfyui_output}") except ImportError: - self.logger.warning(" โš ๏ธ ComfyUI folder_paths not available") + self.logger.warning(" [WARN] ComfyUI folder_paths not available") return { 'status': 'ok' if output_dirs else 'warning', @@ -217,7 +217,7 @@ class GalleryDiagnostics: def check_dependencies(self) -> Dict[str, Any]: """Check required dependencies.""" - self.logger.info("\n๐Ÿ“ฆ Checking Dependencies...") + self.logger.info("\n[PKG] Checking Dependencies...") dependencies = { 'watchdog': False, @@ -229,25 +229,25 @@ class GalleryDiagnostics: try: import watchdog dependencies['watchdog'] = True - self.logger.info(f" โœ… watchdog: {watchdog.__version__}") + self.logger.info(f" [PASS] watchdog: {watchdog.__version__}") except ImportError: - self.logger.error(" โŒ watchdog: NOT INSTALLED") + self.logger.error(" [FAIL] watchdog: NOT INSTALLED") # Check PIL try: from PIL import Image dependencies['PIL'] = True - self.logger.info(f" โœ… PIL (Pillow): Available") + self.logger.info(f" [PASS] PIL (Pillow): Available") except ImportError: - self.logger.error(" โŒ PIL (Pillow): NOT AVAILABLE") + self.logger.error(" [FAIL] PIL (Pillow): NOT AVAILABLE") # Check sqlite3 try: import sqlite3 dependencies['sqlite3'] = True - self.logger.info(f" โœ… sqlite3: {sqlite3.sqlite_version}") + self.logger.info(f" [PASS] sqlite3: {sqlite3.sqlite_version}") except ImportError: - self.logger.error(" โŒ sqlite3: NOT AVAILABLE") + self.logger.error(" [FAIL] sqlite3: NOT AVAILABLE") all_deps_ok = all(dependencies.values()) @@ -259,7 +259,7 @@ class GalleryDiagnostics: def create_test_image_link(self, prompt_id: int, test_image_path: str = None) -> Dict[str, Any]: """Create a test image link to verify the system works.""" - self.logger.info(f"\n๐Ÿงช Creating test image link for prompt {prompt_id}...") + self.logger.info(f"\n[TEST] Creating test image link for prompt {prompt_id}...") try: # Import database operations @@ -292,7 +292,7 @@ class GalleryDiagnostics: metadata=test_metadata ) - self.logger.info(f" โœ… Test image linked with ID: {image_id}") + self.logger.info(f" [PASS] Test image linked with ID: {image_id}") return { 'status': 'ok', From 2615b52a28a1c46383b2072e689f07dc86ca5d12 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Wed, 28 May 2025 09:17:33 -0700 Subject: [PATCH 3/4] style: Update console output format in restart script --- restart_gallery.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/restart_gallery.py b/restart_gallery.py index 6733f6a..b83bae7 100644 --- a/restart_gallery.py +++ b/restart_gallery.py @@ -17,31 +17,31 @@ try: from utils.prompt_tracker import PromptTracker from utils.image_monitor import ImageMonitor - print("๐Ÿ”„ Restarting PromptManager Gallery System...") + print("[RESTART] Restarting PromptManager Gallery System...") # Initialize components db = PromptDatabase() tracker = PromptTracker(db) monitor = ImageMonitor(db, tracker) - print("โœ… Components initialized successfully") + print("[SUCCESS] Components initialized successfully") # Test image monitoring directories status = monitor.get_status() - print(f"๐Ÿ“ Monitoring status: {status}") + print(f"[INFO] Monitoring status: {status}") # Start monitoring monitor.start_monitoring() - print("โœ… Image monitoring restarted") + print("[SUCCESS] Image monitoring restarted") - print("\n๐ŸŽ‰ Gallery system restart completed!") + print("\n[READY] Gallery system restart completed!") print("Generate some images now to test the automatic linking.") except ImportError as e: - print(f"โŒ Import error: {e}") + print(f"[ERROR] Import error: {e}") print("Make sure you're running this from the PromptManager directory") except Exception as e: - print(f"โŒ Error: {e}") + print(f"[ERROR] Error: {e}") import traceback traceback.print_exc() \ No newline at end of file From 719808c5b542f311e08337874f749073b3639ea7 Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Wed, 28 May 2025 09:17:43 -0700 Subject: [PATCH 4/4] style: Update log message format in __init__.py --- __init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__init__.py b/__init__.py index 44dad7f..740be16 100644 --- a/__init__.py +++ b/__init__.py @@ -69,4 +69,4 @@ except Exception as e: __all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS", "WEB_DIRECTORY"] -log_message("โœ… PromptManager custom node loaded successfully!") \ No newline at end of file +log_message("[SUCCESS] PromptManager custom node loaded successfully!") \ No newline at end of file