From cab8239ba878b2fc87be4ec4da206f3f718ea796 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Mon, 14 Aug 2023 20:18:09 -0400 Subject: [PATCH 1/5] add get_logger() as alias for getLogger() --- invokeai/backend/util/logging.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/invokeai/backend/util/logging.py b/invokeai/backend/util/logging.py index 3a8d721aa5..5c511bcab7 100644 --- a/invokeai/backend/util/logging.py +++ b/invokeai/backend/util/logging.py @@ -228,7 +228,6 @@ def basicConfig(**kwargs): def getLogger(name: str = None) -> logging.Logger: return InvokeAILogger.getLogger(name) - _FACILITY_MAP = ( dict( LOG_KERN=syslog.LOG_KERN, @@ -366,6 +365,11 @@ class InvokeAILogger(object): cls.loggers[name] = logger return cls.loggers[name] + # same thing without the camel case + @classmethod + def get_logger(cls, *arg, **kwarg) -> logging.Logger: + return cls.getLogger(*arg, **kwarg) + @classmethod def getLoggers(cls, config: InvokeAIAppConfig) -> list[logging.Handler]: handler_strs = config.log_handlers From 09ef57718e4ddcee7fe6cf715ddd16523f916919 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Mon, 14 Aug 2023 20:20:35 -0400 Subject: [PATCH 2/5] fix docs --- invokeai/backend/util/logging.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/invokeai/backend/util/logging.py b/invokeai/backend/util/logging.py index 5c511bcab7..78634eee16 100644 --- a/invokeai/backend/util/logging.py +++ b/invokeai/backend/util/logging.py @@ -1,7 +1,6 @@ # Copyright (c) 2023 Lincoln D. Stein and The InvokeAI Development Team -""" -invokeai.backend.util.logging +"""invokeai.backend.util.logging Logging class for InvokeAI that produces console messages @@ -40,7 +39,10 @@ object: config = InvokeAIAppConfig.get_config() config.parse_args() - logger = InvokeAILogger.getLogger(config=config) + logger = InvokeAILogger.get_logger(config=config) + +For backward compatibility, getLogger() is an alias for get_logger(), +but without the camel case. ### Three command-line options control logging: @@ -173,6 +175,7 @@ InvokeAI: log_level: info log_format: color ``` + """ import logging.handlers @@ -228,6 +231,7 @@ def basicConfig(**kwargs): def getLogger(name: str = None) -> logging.Logger: return InvokeAILogger.getLogger(name) + _FACILITY_MAP = ( dict( LOG_KERN=syslog.LOG_KERN, From 1d107f30e5992bdbe9d31ee17523329024577cd7 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Thu, 17 Aug 2023 19:17:38 -0400 Subject: [PATCH 3/5] remove getLogger() completely --- invokeai/app/api/dependencies.py | 2 +- invokeai/app/api_app.py | 4 +- invokeai/app/cli_app.py | 2 +- .../backend/install/invokeai_configure.py | 4 +- .../backend/install/model_install_backend.py | 4 +- .../convert_ckpt_to_diffusers.py | 2 +- invokeai/backend/util/logging.py | 40 +++++++------------ invokeai/frontend/install/model_install.py | 6 +-- 8 files changed, 26 insertions(+), 38 deletions(-) diff --git a/invokeai/app/api/dependencies.py b/invokeai/app/api/dependencies.py index 4aaf7a0272..3683d812e9 100644 --- a/invokeai/app/api/dependencies.py +++ b/invokeai/app/api/dependencies.py @@ -49,7 +49,7 @@ def check_internet() -> bool: return False -logger = InvokeAILogger.getLogger() +logger = InvokeAILogger.get_logger() class ApiDependencies: diff --git a/invokeai/app/api_app.py b/invokeai/app/api_app.py index 20b2781ef0..22e9d5ed40 100644 --- a/invokeai/app/api_app.py +++ b/invokeai/app/api_app.py @@ -23,7 +23,7 @@ from ..backend.util.logging import InvokeAILogger app_config = InvokeAIAppConfig.get_config() app_config.parse_args() -logger = InvokeAILogger.getLogger(config=app_config) +logger = InvokeAILogger.get_logger(config=app_config) from invokeai.version.invokeai_version import __version__ # we call this early so that the message appears before @@ -230,7 +230,7 @@ def invoke_api(): # replace uvicorn's loggers with InvokeAI's for consistent appearance for logname in ["uvicorn.access", "uvicorn"]: - l = logging.getLogger(logname) + l = logging.get_logger(logname) l.handlers.clear() for ch in logger.handlers: l.addHandler(ch) diff --git a/invokeai/app/cli_app.py b/invokeai/app/cli_app.py index 4558c9219f..ae05ee9fc6 100644 --- a/invokeai/app/cli_app.py +++ b/invokeai/app/cli_app.py @@ -16,7 +16,7 @@ from invokeai.backend.util.logging import InvokeAILogger config = InvokeAIAppConfig.get_config() config.parse_args() -logger = InvokeAILogger().getLogger(config=config) +logger = InvokeAILogger().get_logger(config=config) from invokeai.version.invokeai_version import __version__ # we call this early so that the message appears before other invokeai initialization messages diff --git a/invokeai/backend/install/invokeai_configure.py b/invokeai/backend/install/invokeai_configure.py index 6996b913c2..be7ff8a306 100755 --- a/invokeai/backend/install/invokeai_configure.py +++ b/invokeai/backend/install/invokeai_configure.py @@ -96,7 +96,7 @@ INIT_FILE_PREAMBLE = """# InvokeAI initialization file # or renaming it and then running invokeai-configure again. """ -logger = InvokeAILogger.getLogger() +logger = InvokeAILogger.get_logger() class DummyWidgetValue(Enum): @@ -827,7 +827,7 @@ def main(): if opt.full_precision: invoke_args.extend(["--precision", "float32"]) config.parse_args(invoke_args) - logger = InvokeAILogger().getLogger(config=config) + logger = InvokeAILogger().get_logger(config=config) errors = set() diff --git a/invokeai/backend/install/model_install_backend.py b/invokeai/backend/install/model_install_backend.py index 3a6d879bee..798345e5bf 100644 --- a/invokeai/backend/install/model_install_backend.py +++ b/invokeai/backend/install/model_install_backend.py @@ -31,7 +31,7 @@ warnings.filterwarnings("ignore") # --------------------------globals----------------------- config = InvokeAIAppConfig.get_config() -logger = InvokeAILogger.getLogger(name="InvokeAI") +logger = InvokeAILogger.get_logger(name="InvokeAI") # the initial "configs" dir is now bundled in the `invokeai.configs` package Dataset_path = Path(configs.__path__[0]) / "INITIAL_MODELS.yaml" @@ -483,7 +483,7 @@ def yes_or_no(prompt: str, default_yes=True): # --------------------------------------------- def hf_download_from_pretrained(model_class: object, model_name: str, destination: Path, **kwargs): - logger = InvokeAILogger.getLogger("InvokeAI") + logger = InvokeAILogger.get_logger("InvokeAI") logger.addFilter(lambda x: "fp16 is not a valid" not in x.getMessage()) model = model_class.from_pretrained( diff --git a/invokeai/backend/model_management/convert_ckpt_to_diffusers.py b/invokeai/backend/model_management/convert_ckpt_to_diffusers.py index 5fd3669911..ae41700b69 100644 --- a/invokeai/backend/model_management/convert_ckpt_to_diffusers.py +++ b/invokeai/backend/model_management/convert_ckpt_to_diffusers.py @@ -80,7 +80,7 @@ if is_accelerate_available(): from accelerate import init_empty_weights from accelerate.utils import set_module_tensor_to_device -logger = InvokeAILogger.getLogger(__name__) +logger = InvokeAILogger.get_logger(__name__) CONVERT_MODEL_ROOT = InvokeAIAppConfig.get_config().models_path / "core/convert" diff --git a/invokeai/backend/util/logging.py b/invokeai/backend/util/logging.py index 78634eee16..efd2689b1c 100644 --- a/invokeai/backend/util/logging.py +++ b/invokeai/backend/util/logging.py @@ -8,9 +8,9 @@ Usage: from invokeai.backend.util.logging import InvokeAILogger -logger = InvokeAILogger.getLogger(name='InvokeAI') // Initialization +logger = InvokeAILogger.get_logger(name='InvokeAI') // Initialization (or) -logger = InvokeAILogger.getLogger(__name__) // To use the filename +logger = InvokeAILogger.get_logger(__name__) // To use the filename logger.configure() logger.critical('this is critical') // Critical Message @@ -33,7 +33,7 @@ IAILogger.debug('this is a debugging message') ## Configuration The default configuration will print to stderr on the console. To add -additional logging handlers, call getLogger with an initialized InvokeAIAppConfig +additional logging handlers, call get_logger with an initialized InvokeAIAppConfig object: @@ -41,9 +41,6 @@ object: config.parse_args() logger = InvokeAILogger.get_logger(config=config) -For backward compatibility, getLogger() is an alias for get_logger(), -but without the camel case. - ### Three command-line options control logging: `--log_handlers ...` @@ -197,39 +194,35 @@ except: # module level functions def debug(msg, *args, **kwargs): - InvokeAILogger.getLogger().debug(msg, *args, **kwargs) + InvokeAILogger.get_logger().debug(msg, *args, **kwargs) def info(msg, *args, **kwargs): - InvokeAILogger.getLogger().info(msg, *args, **kwargs) + InvokeAILogger.get_logger().info(msg, *args, **kwargs) def warning(msg, *args, **kwargs): - InvokeAILogger.getLogger().warning(msg, *args, **kwargs) + InvokeAILogger.get_logger().warning(msg, *args, **kwargs) def error(msg, *args, **kwargs): - InvokeAILogger.getLogger().error(msg, *args, **kwargs) + InvokeAILogger.get_logger().error(msg, *args, **kwargs) def critical(msg, *args, **kwargs): - InvokeAILogger.getLogger().critical(msg, *args, **kwargs) + InvokeAILogger.get_logger().critical(msg, *args, **kwargs) def log(level, msg, *args, **kwargs): - InvokeAILogger.getLogger().log(level, msg, *args, **kwargs) + InvokeAILogger.get_logger().log(level, msg, *args, **kwargs) def disable(level=logging.CRITICAL): - InvokeAILogger.getLogger().disable(level) + InvokeAILogger.get_logger().disable(level) def basicConfig(**kwargs): - InvokeAILogger.getLogger().basicConfig(**kwargs) - - -def getLogger(name: str = None) -> logging.Logger: - return InvokeAILogger.getLogger(name) + InvokeAILogger.get_logger().basicConfig(**kwargs) _FACILITY_MAP = ( @@ -355,7 +348,7 @@ class InvokeAILogger(object): loggers = dict() @classmethod - def getLogger( + def get_logger( cls, name: str = "InvokeAI", config: InvokeAIAppConfig = InvokeAIAppConfig.get_config() ) -> logging.Logger: if name in cls.loggers: @@ -364,18 +357,13 @@ class InvokeAILogger(object): else: logger = logging.getLogger(name) logger.setLevel(config.log_level.upper()) # yes, strings work here - for ch in cls.getLoggers(config): + for ch in cls.get_loggers(config): logger.addHandler(ch) cls.loggers[name] = logger return cls.loggers[name] - # same thing without the camel case @classmethod - def get_logger(cls, *arg, **kwarg) -> logging.Logger: - return cls.getLogger(*arg, **kwarg) - - @classmethod - def getLoggers(cls, config: InvokeAIAppConfig) -> list[logging.Handler]: + def get_loggers(cls, config: InvokeAIAppConfig) -> list[logging.Handler]: handler_strs = config.log_handlers handlers = list() for handler in handler_strs: diff --git a/invokeai/frontend/install/model_install.py b/invokeai/frontend/install/model_install.py index ade3043d96..1153ea313e 100644 --- a/invokeai/frontend/install/model_install.py +++ b/invokeai/frontend/install/model_install.py @@ -50,7 +50,7 @@ from invokeai.frontend.install.widgets import ( from invokeai.app.services.config import InvokeAIAppConfig config = InvokeAIAppConfig.get_config() -logger = InvokeAILogger.getLogger() +logger = InvokeAILogger.get_logger() # build a table mapping all non-printable characters to None # for stripping control characters @@ -657,7 +657,7 @@ def process_and_execute( translator = StderrToMessage(conn_out) sys.stderr = translator sys.stdout = translator - logger = InvokeAILogger.getLogger() + logger = InvokeAILogger.get_logger() logger.handlers.clear() logger.addHandler(logging.StreamHandler(translator)) @@ -771,7 +771,7 @@ def main(): if opt.full_precision: invoke_args.extend(["--precision", "float32"]) config.parse_args(invoke_args) - logger = InvokeAILogger().getLogger(config=config) + logger = InvokeAILogger().get_logger(config=config) if not config.model_conf_path.exists(): logger.info("Your InvokeAI root directory is not set up. Calling invokeai-configure.") From 4570702dd0a220b5856ef6414f653d7b52c25a81 Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Thu, 17 Aug 2023 20:17:10 -0400 Subject: [PATCH 4/5] hotfix for crashing api --- invokeai/app/api_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/invokeai/app/api_app.py b/invokeai/app/api_app.py index 22e9d5ed40..dab3dac2c0 100644 --- a/invokeai/app/api_app.py +++ b/invokeai/app/api_app.py @@ -230,7 +230,7 @@ def invoke_api(): # replace uvicorn's loggers with InvokeAI's for consistent appearance for logname in ["uvicorn.access", "uvicorn"]: - l = logging.get_logger(logname) + l = logging.getLogger(logname) l.handlers.clear() for ch in logger.handlers: l.addHandler(ch) From 58aa159a501fe38dbf8bdf308d4d5edaffbf541a Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Tue, 5 Sep 2023 10:43:30 +1000 Subject: [PATCH 5/5] fix(backend): fix remaining instances of `getLogger()` --- invokeai/app/api_app.py | 5 ++--- invokeai/backend/util/hotfixes.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/invokeai/app/api_app.py b/invokeai/app/api_app.py index 967fc0f960..a0b381477b 100644 --- a/invokeai/app/api_app.py +++ b/invokeai/app/api_app.py @@ -1,6 +1,5 @@ # Copyright (c) 2022-2023 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team import asyncio -import logging import socket from inspect import signature from pathlib import Path @@ -218,7 +217,7 @@ def invoke_api(): exc_info=e, ) else: - jurigged.watch(logger=InvokeAILogger.getLogger(name="jurigged").info) + jurigged.watch(logger=InvokeAILogger.get_logger(name="jurigged").info) port = find_port(app_config.port) if port != app_config.port: @@ -237,7 +236,7 @@ def invoke_api(): # replace uvicorn's loggers with InvokeAI's for consistent appearance for logname in ["uvicorn.access", "uvicorn"]: - log = logging.getLogger(logname) + log = InvokeAILogger.get_logger(logname) log.handlers.clear() for ch in logger.handlers: log.addHandler(ch) diff --git a/invokeai/backend/util/hotfixes.py b/invokeai/backend/util/hotfixes.py index 983d0b7601..42ca5d08ee 100644 --- a/invokeai/backend/util/hotfixes.py +++ b/invokeai/backend/util/hotfixes.py @@ -24,7 +24,7 @@ from invokeai.backend.util.logging import InvokeAILogger # Modified ControlNetModel with encoder_attention_mask argument added -logger = InvokeAILogger.getLogger(__name__) +logger = InvokeAILogger.get_logger(__name__) class ControlNetModel(ModelMixin, ConfigMixin, FromOriginalControlnetMixin):