diff --git a/invokeai/app/cli_app.py b/invokeai/app/cli_app.py index 5d8673a958..3db7c3eb9c 100644 --- a/invokeai/app/cli_app.py +++ b/invokeai/app/cli_app.py @@ -13,14 +13,20 @@ from typing import ( from pydantic import BaseModel, ValidationError from pydantic.fields import Field + +# This should come early so that the logger can pick up its configuration options +from .services.config import InvokeAIAppConfig +from invokeai.backend.util.logging import InvokeAILogger +config = InvokeAIAppConfig.get_config() +config.parse_args() +logger = InvokeAILogger().getLogger(config=config) + from invokeai.app.services.image_record_storage import SqliteImageRecordStorage from invokeai.app.services.images import ImageService from invokeai.app.services.metadata import CoreMetadataService from invokeai.app.services.resource_name import SimpleNameService from invokeai.app.services.urls import LocalUrlService - -import invokeai.backend.util.logging as logger from .services.default_graphs import create_system_graphs from .services.latent_storage import DiskLatentsStorage, ForwardCacheLatentsStorage @@ -38,7 +44,7 @@ from .services.invocation_services import InvocationServices from .services.invoker import Invoker from .services.processor import DefaultInvocationProcessor from .services.sqlite import SqliteItemStorage -from .services.config import InvokeAIAppConfig + class CliCommand(BaseModel): command: Union[BaseCommand.get_commands() + BaseInvocation.get_invocations()] = Field(discriminator="type") # type: ignore @@ -47,7 +53,6 @@ class CliCommand(BaseModel): class InvalidArgs(Exception): pass - def add_invocation_args(command_parser): # Add linking capability command_parser.add_argument( @@ -191,15 +196,8 @@ def invoke_all(context: CliContext): raise SessionError() - -logger = logger.InvokeAILogger.getLogger() - - def invoke_cli(): - # this gets the basic configuration - config = InvokeAIAppConfig.get_config() - config.parse_args() - + # get the optional list of invocations to execute on the command line parser = config.get_parser() parser.add_argument('commands',nargs='*') diff --git a/invokeai/backend/model_management/model_manager.py b/invokeai/backend/model_management/model_manager.py index 8e80c0b5c4..5ef1d33302 100644 --- a/invokeai/backend/model_management/model_manager.py +++ b/invokeai/backend/model_management/model_manager.py @@ -777,7 +777,7 @@ class ModelManager(object): self.logger.info(f"Probing {thing} for import") - if thing.startswith(("http:", "https:", "ftp:")): + if str(thing).startswith(("http:", "https:", "ftp:")): self.logger.info(f"{thing} appears to be a URL") model_path = self._resolve_path( thing, "models/ldm/stable-diffusion-v1" diff --git a/invokeai/backend/util/logging.py b/invokeai/backend/util/logging.py index 16efd56c03..0bb62bc1c2 100644 --- a/invokeai/backend/util/logging.py +++ b/invokeai/backend/util/logging.py @@ -181,9 +181,11 @@ class InvokeAILogger(object): loggers = dict() @classmethod - def getLogger(cls, name: str = 'InvokeAI') -> logging.Logger: - config = get_invokeai_config() - + def getLogger(cls, name: str = 'InvokeAI', config: InvokeAIAppConfig=None) -> logging.Logger: + if not config: + config = InvokeAIAppConfig() + config.parse_args() + if name not in cls.loggers: logger = logging.getLogger(name) logger.setLevel(config.log_level.upper()) # yes, strings work here @@ -195,15 +197,16 @@ class InvokeAILogger(object): @classmethod def getLoggers(cls, config: InvokeAIAppConfig) -> list[logging.Handler]: handler_strs = config.log_handlers - print(f'handler_strs={handler_strs}') handlers = list() for handler in handler_strs: handler_name,*args = handler.split('=',2) args = args[0] if len(args) > 0 else None - # console is the only handler that gets a custom formatter + # console and file get the fancy formatter. + # syslog gets a simple one + # http gets no custom formatter + formatter = LOG_FORMATTERS[config.log_format] if handler_name=='console': - formatter = LOG_FORMATTERS[config.log_format] ch = logging.StreamHandler() ch.setFormatter(formatter()) handlers.append(ch) @@ -214,7 +217,9 @@ class InvokeAILogger(object): handlers.append(ch) elif handler_name=='file': - handlers.append(cls._parse_file_args(args)) + ch = cls._parse_file_args(args) + ch.setFormatter(formatter()) + handlers.append(ch) elif handler_name=='http': handlers.append(cls._parse_http_args(args))