remove getLogger() completely

This commit is contained in:
Lincoln Stein 2023-08-17 19:17:38 -04:00
parent 79084e9e20
commit 1d107f30e5
8 changed files with 26 additions and 38 deletions

View File

@ -49,7 +49,7 @@ def check_internet() -> bool:
return False return False
logger = InvokeAILogger.getLogger() logger = InvokeAILogger.get_logger()
class ApiDependencies: class ApiDependencies:

View File

@ -23,7 +23,7 @@ from ..backend.util.logging import InvokeAILogger
app_config = InvokeAIAppConfig.get_config() app_config = InvokeAIAppConfig.get_config()
app_config.parse_args() app_config.parse_args()
logger = InvokeAILogger.getLogger(config=app_config) logger = InvokeAILogger.get_logger(config=app_config)
from invokeai.version.invokeai_version import __version__ from invokeai.version.invokeai_version import __version__
# we call this early so that the message appears before # 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 # replace uvicorn's loggers with InvokeAI's for consistent appearance
for logname in ["uvicorn.access", "uvicorn"]: for logname in ["uvicorn.access", "uvicorn"]:
l = logging.getLogger(logname) l = logging.get_logger(logname)
l.handlers.clear() l.handlers.clear()
for ch in logger.handlers: for ch in logger.handlers:
l.addHandler(ch) l.addHandler(ch)

View File

@ -16,7 +16,7 @@ from invokeai.backend.util.logging import InvokeAILogger
config = InvokeAIAppConfig.get_config() config = InvokeAIAppConfig.get_config()
config.parse_args() config.parse_args()
logger = InvokeAILogger().getLogger(config=config) logger = InvokeAILogger().get_logger(config=config)
from invokeai.version.invokeai_version import __version__ from invokeai.version.invokeai_version import __version__
# we call this early so that the message appears before other invokeai initialization messages # we call this early so that the message appears before other invokeai initialization messages

View File

@ -96,7 +96,7 @@ INIT_FILE_PREAMBLE = """# InvokeAI initialization file
# or renaming it and then running invokeai-configure again. # or renaming it and then running invokeai-configure again.
""" """
logger = InvokeAILogger.getLogger() logger = InvokeAILogger.get_logger()
class DummyWidgetValue(Enum): class DummyWidgetValue(Enum):
@ -827,7 +827,7 @@ def main():
if opt.full_precision: if opt.full_precision:
invoke_args.extend(["--precision", "float32"]) invoke_args.extend(["--precision", "float32"])
config.parse_args(invoke_args) config.parse_args(invoke_args)
logger = InvokeAILogger().getLogger(config=config) logger = InvokeAILogger().get_logger(config=config)
errors = set() errors = set()

View File

@ -31,7 +31,7 @@ warnings.filterwarnings("ignore")
# --------------------------globals----------------------- # --------------------------globals-----------------------
config = InvokeAIAppConfig.get_config() 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 # the initial "configs" dir is now bundled in the `invokeai.configs` package
Dataset_path = Path(configs.__path__[0]) / "INITIAL_MODELS.yaml" 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): 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()) logger.addFilter(lambda x: "fp16 is not a valid" not in x.getMessage())
model = model_class.from_pretrained( model = model_class.from_pretrained(

View File

@ -80,7 +80,7 @@ if is_accelerate_available():
from accelerate import init_empty_weights from accelerate import init_empty_weights
from accelerate.utils import set_module_tensor_to_device 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" CONVERT_MODEL_ROOT = InvokeAIAppConfig.get_config().models_path / "core/convert"

View File

@ -8,9 +8,9 @@ Usage:
from invokeai.backend.util.logging import InvokeAILogger from invokeai.backend.util.logging import InvokeAILogger
logger = InvokeAILogger.getLogger(name='InvokeAI') // Initialization logger = InvokeAILogger.get_logger(name='InvokeAI') // Initialization
(or) (or)
logger = InvokeAILogger.getLogger(__name__) // To use the filename logger = InvokeAILogger.get_logger(__name__) // To use the filename
logger.configure() logger.configure()
logger.critical('this is critical') // Critical Message logger.critical('this is critical') // Critical Message
@ -33,7 +33,7 @@ IAILogger.debug('this is a debugging message')
## Configuration ## Configuration
The default configuration will print to stderr on the console. To add 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: object:
@ -41,9 +41,6 @@ object:
config.parse_args() config.parse_args()
logger = InvokeAILogger.get_logger(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: ### Three command-line options control logging:
`--log_handlers <handler1> <handler2> ...` `--log_handlers <handler1> <handler2> ...`
@ -197,39 +194,35 @@ except:
# module level functions # module level functions
def debug(msg, *args, **kwargs): def debug(msg, *args, **kwargs):
InvokeAILogger.getLogger().debug(msg, *args, **kwargs) InvokeAILogger.get_logger().debug(msg, *args, **kwargs)
def info(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): def warning(msg, *args, **kwargs):
InvokeAILogger.getLogger().warning(msg, *args, **kwargs) InvokeAILogger.get_logger().warning(msg, *args, **kwargs)
def error(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): def critical(msg, *args, **kwargs):
InvokeAILogger.getLogger().critical(msg, *args, **kwargs) InvokeAILogger.get_logger().critical(msg, *args, **kwargs)
def log(level, 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): def disable(level=logging.CRITICAL):
InvokeAILogger.getLogger().disable(level) InvokeAILogger.get_logger().disable(level)
def basicConfig(**kwargs): def basicConfig(**kwargs):
InvokeAILogger.getLogger().basicConfig(**kwargs) InvokeAILogger.get_logger().basicConfig(**kwargs)
def getLogger(name: str = None) -> logging.Logger:
return InvokeAILogger.getLogger(name)
_FACILITY_MAP = ( _FACILITY_MAP = (
@ -355,7 +348,7 @@ class InvokeAILogger(object):
loggers = dict() loggers = dict()
@classmethod @classmethod
def getLogger( def get_logger(
cls, name: str = "InvokeAI", config: InvokeAIAppConfig = InvokeAIAppConfig.get_config() cls, name: str = "InvokeAI", config: InvokeAIAppConfig = InvokeAIAppConfig.get_config()
) -> logging.Logger: ) -> logging.Logger:
if name in cls.loggers: if name in cls.loggers:
@ -364,18 +357,13 @@ class InvokeAILogger(object):
else: else:
logger = logging.getLogger(name) logger = logging.getLogger(name)
logger.setLevel(config.log_level.upper()) # yes, strings work here 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) logger.addHandler(ch)
cls.loggers[name] = logger cls.loggers[name] = logger
return cls.loggers[name] return cls.loggers[name]
# same thing without the camel case
@classmethod @classmethod
def get_logger(cls, *arg, **kwarg) -> logging.Logger: def get_loggers(cls, config: InvokeAIAppConfig) -> list[logging.Handler]:
return cls.getLogger(*arg, **kwarg)
@classmethod
def getLoggers(cls, config: InvokeAIAppConfig) -> list[logging.Handler]:
handler_strs = config.log_handlers handler_strs = config.log_handlers
handlers = list() handlers = list()
for handler in handler_strs: for handler in handler_strs:

View File

@ -50,7 +50,7 @@ from invokeai.frontend.install.widgets import (
from invokeai.app.services.config import InvokeAIAppConfig from invokeai.app.services.config import InvokeAIAppConfig
config = InvokeAIAppConfig.get_config() config = InvokeAIAppConfig.get_config()
logger = InvokeAILogger.getLogger() logger = InvokeAILogger.get_logger()
# build a table mapping all non-printable characters to None # build a table mapping all non-printable characters to None
# for stripping control characters # for stripping control characters
@ -657,7 +657,7 @@ def process_and_execute(
translator = StderrToMessage(conn_out) translator = StderrToMessage(conn_out)
sys.stderr = translator sys.stderr = translator
sys.stdout = translator sys.stdout = translator
logger = InvokeAILogger.getLogger() logger = InvokeAILogger.get_logger()
logger.handlers.clear() logger.handlers.clear()
logger.addHandler(logging.StreamHandler(translator)) logger.addHandler(logging.StreamHandler(translator))
@ -771,7 +771,7 @@ def main():
if opt.full_precision: if opt.full_precision:
invoke_args.extend(["--precision", "float32"]) invoke_args.extend(["--precision", "float32"])
config.parse_args(invoke_args) config.parse_args(invoke_args)
logger = InvokeAILogger().getLogger(config=config) logger = InvokeAILogger().get_logger(config=config)
if not config.model_conf_path.exists(): if not config.model_conf_path.exists():
logger.info("Your InvokeAI root directory is not set up. Calling invokeai-configure.") logger.info("Your InvokeAI root directory is not set up. Calling invokeai-configure.")