From d14b02e93fd5d86e8516986750cc54c5550e45f6 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 21 May 2023 20:24:37 +1000 Subject: [PATCH] feat(logger): fix logger type issues --- invokeai/app/api/dependencies.py | 7 +++++-- invokeai/app/services/invocation_services.py | 7 ++----- invokeai/backend/util/logging.py | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/invokeai/app/api/dependencies.py b/invokeai/app/api/dependencies.py index e0fe960ea0..9a8816a5f2 100644 --- a/invokeai/app/api/dependencies.py +++ b/invokeai/app/api/dependencies.py @@ -1,12 +1,12 @@ # Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) +from logging import Logger import os from types import ModuleType from invokeai.app.services.image_record_storage import SqliteImageRecordStorage from invokeai.app.services.images import ImageService from invokeai.app.services.urls import LocalUrlService - -import invokeai.backend.util.logging as logger +from invokeai.backend.util.logging import InvokeAILogger from ..services.default_graphs import create_system_graphs from ..services.latent_storage import DiskLatentsStorage, ForwardCacheLatentsStorage @@ -40,6 +40,9 @@ def check_internet() -> bool: return False +logger = InvokeAILogger.getLogger() + + class ApiDependencies: """Contains and initializes all dependencies for the API""" diff --git a/invokeai/app/services/invocation_services.py b/invokeai/app/services/invocation_services.py index 37a6a02e73..ab6069b7c0 100644 --- a/invokeai/app/services/invocation_services.py +++ b/invokeai/app/services/invocation_services.py @@ -1,9 +1,6 @@ # Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) and the InvokeAI Team -from types import ModuleType -from invokeai.app.services.image_record_storage import ( - ImageRecordStorageBase, -) +from logging import Logger from invokeai.app.services.images import ImageService from invokeai.app.services.metadata import MetadataServiceBase from invokeai.app.services.urls import UrlServiceBase @@ -41,7 +38,7 @@ class InvocationServices: self, model_manager: ModelManager, events: EventServiceBase, - logger: ModuleType, + logger: Logger, latents: LatentsStorageBase, images: ImageFileStorageBase, metadata: MetadataServiceBase, diff --git a/invokeai/backend/util/logging.py b/invokeai/backend/util/logging.py index 3822ccafbe..9d1262d5c6 100644 --- a/invokeai/backend/util/logging.py +++ b/invokeai/backend/util/logging.py @@ -76,16 +76,16 @@ class InvokeAILogFormatter(logging.Formatter): reset = "\x1b[0m" # Log Format - format = "[%(asctime)s]::[%(name)s]::%(levelname)s --> %(message)s" + log_format = "[%(asctime)s]::[%(name)s]::%(levelname)s --> %(message)s" ## More Formatting Options: %(pathname)s, %(filename)s, %(module)s, %(lineno)d # Format Map FORMATS = { - logging.DEBUG: cyan + format + reset, - logging.INFO: grey + format + reset, - logging.WARNING: yellow + format + reset, - logging.ERROR: red + format + reset, - logging.CRITICAL: bold_red + format + reset + logging.DEBUG: cyan + log_format + reset, + logging.INFO: grey + log_format + reset, + logging.WARNING: yellow + log_format + reset, + logging.ERROR: red + log_format + reset, + logging.CRITICAL: bold_red + log_format + reset } def format(self, record): @@ -98,13 +98,13 @@ class InvokeAILogger(object): loggers = dict() @classmethod - def getLogger(self, name: str = 'InvokeAI') -> logging.Logger: - if name not in self.loggers: + def getLogger(cls, name: str = 'InvokeAI') -> logging.Logger: + if name not in cls.loggers: logger = logging.getLogger(name) logger.setLevel(logging.DEBUG) ch = logging.StreamHandler() fmt = InvokeAILogFormatter() ch.setFormatter(fmt) logger.addHandler(ch) - self.loggers[name] = logger - return self.loggers[name] + cls.loggers[name] = logger + return cls.loggers[name]