mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
feat: add logging setup and standalone mode detection to LoRA Manager
- Initialize logging configuration via `setup_logging()` when not in standalone mode - Detect standalone mode using environment variables `LORA_MANAGER_STANDALONE` and `HF_HUB_DISABLE_TELEMETRY` - Remove redundant `STANDALONE_MODE` variable that previously checked `sys.modules`
This commit is contained in:
26
py/utils/logging_config.py
Normal file
26
py/utils/logging_config.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import logging
|
||||
import os
|
||||
|
||||
def setup_logging():
|
||||
"""
|
||||
Sets up a global log record factory that prepends '[LoRA-Manager]' to all logs
|
||||
generated by this extension.
|
||||
"""
|
||||
# project_root should be the parent of the directory containing this file (py/utils/logging_config.py)
|
||||
# So project_root is ComfyUI-Lora-Manager/
|
||||
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
prefix = "[LoRA-Manager] "
|
||||
|
||||
old_factory = logging.getLogRecordFactory()
|
||||
def factory(*args, **kwargs):
|
||||
record = old_factory(*args, **kwargs)
|
||||
|
||||
# Check if the log is coming from our extension
|
||||
# We use pathname to verify if it's within our project directory
|
||||
if record.pathname and os.path.abspath(record.pathname).startswith(project_root):
|
||||
if isinstance(record.msg, str) and not record.msg.startswith(prefix):
|
||||
record.msg = f"{prefix}{record.msg}"
|
||||
|
||||
return record
|
||||
|
||||
logging.setLogRecordFactory(factory)
|
||||
Reference in New Issue
Block a user