From d796ea7becb5c4db4417bb9a2ac7d03cc3a7445a Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Sat, 13 May 2023 02:13:49 +1200 Subject: [PATCH 1/4] feat: Logging Improvements --- invokeai/backend/util/logging.py | 98 ++++++++++++++++---------------- scripts/invoke-new.py | 3 + 2 files changed, 52 insertions(+), 49 deletions(-) diff --git a/invokeai/backend/util/logging.py b/invokeai/backend/util/logging.py index 73f980aeff..523aa42d7d 100644 --- a/invokeai/backend/util/logging.py +++ b/invokeai/backend/util/logging.py @@ -2,34 +2,37 @@ """invokeai.util.logging -Logging class for InvokeAI that produces console messages that follow -the conventions established in InvokeAI 1.X through 2.X. +Logging class for InvokeAI that produces console messages - -One way to use it: +Usage: from invokeai.backend.util.logging import InvokeAILogger -logger = InvokeAILogger.getLogger(__name__) -logger.critical('this is critical') -logger.error('this is an error') -logger.warning('this is a warning') -logger.info('this is info') -logger.debug('this is debugging') +logger = InvokeAILogger.getLogger(name='InvokeAI') // Initialization +(or) +logger = InvokeAILogger.getLogger(__name__) // To use the filename + +logger.critical('this is critical') // Critical Message +logger.error('this is an error') // Error Message +logger.warning('this is a warning') // Warning Message +logger.info('this is info') // Info Message +logger.debug('this is debugging') // Debug Message Console messages: - ### this is critical - *** this is an error *** - ** this is a warning - >> this is info - | this is debugging + [12-05-2023 20]::[InvokeAI]::CRITICAL --> This is an info message [In Bold Red] + [12-05-2023 20]::[InvokeAI]::ERROR --> This is an info message [In Red] + [12-05-2023 20]::[InvokeAI]::WARNING --> This is an info message [In Yellow] + [12-05-2023 20]::[InvokeAI]::INFO --> This is an info message [In Grey] + [12-05-2023 20]::[InvokeAI]::DEBUG --> This is an info message [In Grey] -Another way: -import invokeai.backend.util.logging as ialog -ialogger.debug('this is a debugging message') +Alternate Method (in this case the logger name will be set to InvokeAI): +import invokeai.backend.util.logging as IAILogger +IAILogger.debug('this is a debugging message') """ + import logging + # module level functions def debug(msg, *args, **kwargs): InvokeAILogger.getLogger().debug(msg, *args, **kwargs) @@ -42,7 +45,7 @@ def warning(msg, *args, **kwargs): def error(msg, *args, **kwargs): InvokeAILogger.getLogger().error(msg, *args, **kwargs) - + def critical(msg, *args, **kwargs): InvokeAILogger.getLogger().critical(msg, *args, **kwargs) @@ -55,49 +58,46 @@ def disable(level=logging.CRITICAL): def basicConfig(**kwargs): InvokeAILogger.getLogger().basicConfig(**kwargs) -def getLogger(name: str=None)->logging.Logger: +def getLogger(name: str = None) -> logging.Logger: return InvokeAILogger.getLogger(name) + class InvokeAILogFormatter(logging.Formatter): ''' - Repurposed from: - https://stackoverflow.com/questions/14844970/modifying-logging-message-format-based-on-message-logging-level-in-python3 + Custom Formatting for the InvokeAI Logger ''' - crit_fmt = "### %(msg)s" - err_fmt = "*** %(msg)s" - warn_fmt = "** %(msg)s" - info_fmt = ">> %(msg)s" - dbg_fmt = " | %(msg)s" - def __init__(self): - super().__init__(fmt="%(levelno)d: %(msg)s", datefmt=None, style='%') + # Color Codes + grey = "\x1b[38;20m" + yellow = "\x1b[33;20m" + red = "\x1b[31;20m" + bold_red = "\x1b[31;1m" + reset = "\x1b[0m" + + # Log Format + 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: grey + format + reset, + logging.INFO: grey + format + reset, + logging.WARNING: yellow + format + reset, + logging.ERROR: red + format + reset, + logging.CRITICAL: bold_red + format + reset + } def format(self, record): - # Remember the format used when the logging module - # was installed (in the event that this formatter is - # used with the vanilla logging module. - format_orig = self._style._fmt - if record.levelno == logging.DEBUG: - self._style._fmt = InvokeAILogFormatter.dbg_fmt - if record.levelno == logging.INFO: - self._style._fmt = InvokeAILogFormatter.info_fmt - if record.levelno == logging.WARNING: - self._style._fmt = InvokeAILogFormatter.warn_fmt - if record.levelno == logging.ERROR: - self._style._fmt = InvokeAILogFormatter.err_fmt - if record.levelno == logging.CRITICAL: - self._style._fmt = InvokeAILogFormatter.crit_fmt + log_fmt = self.FORMATS.get(record.levelno) + formatter = logging.Formatter(log_fmt, datefmt="%d-%m-%Y %H:%M:%S") + return formatter.format(record) - # parent class does the work - result = super().format(record) - self._style._fmt = format_orig - return result class InvokeAILogger(object): loggers = dict() - + @classmethod - def getLogger(self, name:str='invokeai')->logging.Logger: + def getLogger(self, name: str = 'InvokeAI') -> logging.Logger: if name not in self.loggers: logger = logging.getLogger(name) logger.setLevel(logging.DEBUG) diff --git a/scripts/invoke-new.py b/scripts/invoke-new.py index a47d6238bd..faf83a9993 100755 --- a/scripts/invoke-new.py +++ b/scripts/invoke-new.py @@ -2,6 +2,9 @@ # Copyright (c) 2022 Kyle Schouviller (https://github.com/kyle0654) +import logging +logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage()) + import os import sys From 691e1bf829f455b2c97f00375c010b92e164e437 Mon Sep 17 00:00:00 2001 From: blessedcoolant <54517381+blessedcoolant@users.noreply.github.com> Date: Sun, 14 May 2023 09:06:57 +1200 Subject: [PATCH 2/4] Make debug messages cyan/blue --- invokeai/backend/util/logging.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/invokeai/backend/util/logging.py b/invokeai/backend/util/logging.py index 523aa42d7d..3822ccafbe 100644 --- a/invokeai/backend/util/logging.py +++ b/invokeai/backend/util/logging.py @@ -71,6 +71,7 @@ class InvokeAILogFormatter(logging.Formatter): grey = "\x1b[38;20m" yellow = "\x1b[33;20m" red = "\x1b[31;20m" + cyan = "\x1b[36;20m" bold_red = "\x1b[31;1m" reset = "\x1b[0m" @@ -80,7 +81,7 @@ class InvokeAILogFormatter(logging.Formatter): # Format Map FORMATS = { - logging.DEBUG: grey + format + reset, + logging.DEBUG: cyan + format + reset, logging.INFO: grey + format + reset, logging.WARNING: yellow + format + reset, logging.ERROR: red + format + reset, From dac82adb5b61ed953e129b89f0db8faa6ce92af2 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 14 May 2023 18:41:11 +1000 Subject: [PATCH 3/4] fix(ui): make logo component non-selectable --- .../system/components/InvokeAILogoComponent.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/invokeai/frontend/web/src/features/system/components/InvokeAILogoComponent.tsx b/invokeai/frontend/web/src/features/system/components/InvokeAILogoComponent.tsx index e736450563..a38a751b8b 100644 --- a/invokeai/frontend/web/src/features/system/components/InvokeAILogoComponent.tsx +++ b/invokeai/frontend/web/src/features/system/components/InvokeAILogoComponent.tsx @@ -17,8 +17,17 @@ const InvokeAILogoComponent = () => { h="32px" minW="32px" minH="32px" + userSelect="none" /> - + invoke ai From f5df1500973ef73accd886b47a0b2a4382a7ca8f Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 14 May 2023 18:42:15 +1000 Subject: [PATCH 4/4] feat(ui): add callback to signal app is ready needed for commercial --- .../frontend/web/src/app/components/App.tsx | 17 ++++++++++++++++- .../web/src/app/components/InvokeAIUI.tsx | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/invokeai/frontend/web/src/app/components/App.tsx b/invokeai/frontend/web/src/app/components/App.tsx index 3fbcbc49ea..eb6496f43e 100644 --- a/invokeai/frontend/web/src/app/components/App.tsx +++ b/invokeai/frontend/web/src/app/components/App.tsx @@ -30,9 +30,14 @@ const DEFAULT_CONFIG = {}; interface Props { config?: PartialAppConfig; headerComponent?: ReactNode; + setIsReady?: (isReady: boolean) => void; } -const App = ({ config = DEFAULT_CONFIG, headerComponent }: Props) => { +const App = ({ + config = DEFAULT_CONFIG, + headerComponent, + setIsReady, +}: Props) => { useToastWatcher(); useGlobalHotkeys(); @@ -61,6 +66,16 @@ const App = ({ config = DEFAULT_CONFIG, headerComponent }: Props) => { setLoadingOverridden(true); }, []); + useEffect(() => { + if (isApplicationReady && setIsReady) { + setIsReady(true); + } + + return () => { + setIsReady && setIsReady(false); + }; + }, [isApplicationReady, setIsReady]); + return ( {isLightboxEnabled && } diff --git a/invokeai/frontend/web/src/app/components/InvokeAIUI.tsx b/invokeai/frontend/web/src/app/components/InvokeAIUI.tsx index 442c1d967a..c04a8184d7 100644 --- a/invokeai/frontend/web/src/app/components/InvokeAIUI.tsx +++ b/invokeai/frontend/web/src/app/components/InvokeAIUI.tsx @@ -24,9 +24,16 @@ interface Props extends PropsWithChildren { token?: string; config?: PartialAppConfig; headerComponent?: ReactNode; + setIsReady?: (isReady: boolean) => void; } -const InvokeAIUI = ({ apiUrl, token, config, headerComponent }: Props) => { +const InvokeAIUI = ({ + apiUrl, + token, + config, + headerComponent, + setIsReady, +}: Props) => { useEffect(() => { // configure API client token if (token) { @@ -55,7 +62,11 @@ const InvokeAIUI = ({ apiUrl, token, config, headerComponent }: Props) => { }> - +