mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
refactor(logging): replace print statements with logger for consistency
This commit is contained in:
@@ -8,6 +8,9 @@ from ..metadata_collector.metadata_processor import MetadataProcessor
|
|||||||
from ..metadata_collector import get_metadata
|
from ..metadata_collector import get_metadata
|
||||||
from PIL import Image, PngImagePlugin
|
from PIL import Image, PngImagePlugin
|
||||||
import piexif
|
import piexif
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class SaveImageLM:
|
class SaveImageLM:
|
||||||
NAME = "Save Image (LoraManager)"
|
NAME = "Save Image (LoraManager)"
|
||||||
@@ -385,7 +388,7 @@ class SaveImageLM:
|
|||||||
exif_bytes = piexif.dump(exif_dict)
|
exif_bytes = piexif.dump(exif_dict)
|
||||||
save_kwargs["exif"] = exif_bytes
|
save_kwargs["exif"] = exif_bytes
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error adding EXIF data: {e}")
|
logger.error(f"Error adding EXIF data: {e}")
|
||||||
img.save(file_path, format="JPEG", **save_kwargs)
|
img.save(file_path, format="JPEG", **save_kwargs)
|
||||||
elif file_format == "webp":
|
elif file_format == "webp":
|
||||||
try:
|
try:
|
||||||
@@ -403,7 +406,7 @@ class SaveImageLM:
|
|||||||
exif_bytes = piexif.dump(exif_dict)
|
exif_bytes = piexif.dump(exif_dict)
|
||||||
save_kwargs["exif"] = exif_bytes
|
save_kwargs["exif"] = exif_bytes
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error adding EXIF data: {e}")
|
logger.error(f"Error adding EXIF data: {e}")
|
||||||
|
|
||||||
img.save(file_path, format="WEBP", **save_kwargs)
|
img.save(file_path, format="WEBP", **save_kwargs)
|
||||||
|
|
||||||
@@ -414,7 +417,7 @@ class SaveImageLM:
|
|||||||
})
|
})
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error saving image: {e}")
|
logger.error(f"Error saving image: {e}")
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|||||||
@@ -30,36 +30,36 @@ class LoraScanner(ModelScanner):
|
|||||||
|
|
||||||
async def diagnose_hash_index(self):
|
async def diagnose_hash_index(self):
|
||||||
"""Diagnostic method to verify hash index functionality"""
|
"""Diagnostic method to verify hash index functionality"""
|
||||||
print("\n\n*** DIAGNOSING LORA HASH INDEX ***\n\n", file=sys.stderr)
|
logger.debug("\n\n*** DIAGNOSING LORA HASH INDEX ***\n\n")
|
||||||
|
|
||||||
# First check if the hash index has any entries
|
# First check if the hash index has any entries
|
||||||
if hasattr(self, '_hash_index'):
|
if hasattr(self, '_hash_index'):
|
||||||
index_entries = len(self._hash_index._hash_to_path)
|
index_entries = len(self._hash_index._hash_to_path)
|
||||||
print(f"Hash index has {index_entries} entries", file=sys.stderr)
|
logger.debug(f"Hash index has {index_entries} entries")
|
||||||
|
|
||||||
# Print a few example entries if available
|
# Print a few example entries if available
|
||||||
if index_entries > 0:
|
if index_entries > 0:
|
||||||
print("\nSample hash index entries:", file=sys.stderr)
|
logger.debug("\nSample hash index entries:")
|
||||||
count = 0
|
count = 0
|
||||||
for hash_val, path in self._hash_index._hash_to_path.items():
|
for hash_val, path in self._hash_index._hash_to_path.items():
|
||||||
if count < 5: # Just show the first 5
|
if count < 5: # Just show the first 5
|
||||||
print(f"Hash: {hash_val[:8]}... -> Path: {path}", file=sys.stderr)
|
logger.debug(f"Hash: {hash_val[:8]}... -> Path: {path}")
|
||||||
count += 1
|
count += 1
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Hash index not initialized", file=sys.stderr)
|
logger.debug("Hash index not initialized")
|
||||||
|
|
||||||
# Try looking up by a known hash for testing
|
# Try looking up by a known hash for testing
|
||||||
if not hasattr(self, '_hash_index') or not self._hash_index._hash_to_path:
|
if not hasattr(self, '_hash_index') or not self._hash_index._hash_to_path:
|
||||||
print("No hash entries to test lookup with", file=sys.stderr)
|
logger.debug("No hash entries to test lookup with")
|
||||||
return
|
return
|
||||||
|
|
||||||
test_hash = next(iter(self._hash_index._hash_to_path.keys()))
|
test_hash = next(iter(self._hash_index._hash_to_path.keys()))
|
||||||
test_path = self._hash_index.get_path(test_hash)
|
test_path = self._hash_index.get_path(test_hash)
|
||||||
print(f"\nTest lookup by hash: {test_hash[:8]}... -> {test_path}", file=sys.stderr)
|
logger.debug(f"\nTest lookup by hash: {test_hash[:8]}... -> {test_path}")
|
||||||
|
|
||||||
# Also test reverse lookup
|
# Also test reverse lookup
|
||||||
test_hash_result = self._hash_index.get_hash(test_path)
|
test_hash_result = self._hash_index.get_hash(test_path)
|
||||||
print(f"Test reverse lookup: {test_path} -> {test_hash_result[:8]}...\n\n", file=sys.stderr)
|
logger.debug(f"Test reverse lookup: {test_path} -> {test_hash_result[:8]}...\n\n")
|
||||||
|
|
||||||
|
|||||||
@@ -686,7 +686,6 @@ class ModelScanner:
|
|||||||
|
|
||||||
async def _initialize_cache(self) -> None:
|
async def _initialize_cache(self) -> None:
|
||||||
"""Initialize or refresh the cache"""
|
"""Initialize or refresh the cache"""
|
||||||
print("init start", flush=True)
|
|
||||||
self._is_initializing = True # Set flag
|
self._is_initializing = True # Set flag
|
||||||
try:
|
try:
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
@@ -700,7 +699,6 @@ class ModelScanner:
|
|||||||
scan_result = await self._gather_model_data()
|
scan_result = await self._gather_model_data()
|
||||||
await self._apply_scan_result(scan_result)
|
await self._apply_scan_result(scan_result)
|
||||||
await self._save_persistent_cache(scan_result)
|
await self._save_persistent_cache(scan_result)
|
||||||
print("init end", flush=True)
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"{self.model_type.capitalize()} Scanner: Cache initialization completed in {time.time() - start_time:.2f} seconds, "
|
f"{self.model_type.capitalize()} Scanner: Cache initialization completed in {time.time() - start_time:.2f} seconds, "
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ async def extract_lora_metadata(file_path: str) -> Dict:
|
|||||||
base_model = determine_base_model(metadata.get("ss_base_model_version"))
|
base_model = determine_base_model(metadata.get("ss_base_model_version"))
|
||||||
return {"base_model": base_model}
|
return {"base_model": base_model}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error reading metadata from {file_path}: {str(e)}")
|
logger.error(f"Error reading metadata from {file_path}: {str(e)}")
|
||||||
return {"base_model": "Unknown"}
|
return {"base_model": "Unknown"}
|
||||||
|
|
||||||
async def extract_checkpoint_metadata(file_path: str) -> dict:
|
async def extract_checkpoint_metadata(file_path: str) -> dict:
|
||||||
|
|||||||
Reference in New Issue
Block a user