refactor: log indentation via formatter

Replace manual indentation with a context-aware logging formatter.
pull/55/head
Bryce 2 years ago committed by Bryce Drennan
parent df3c752eb8
commit 7ae77faf07

@ -181,12 +181,12 @@ def imagine(
precision
), fix_torch_nn_layer_norm(), fix_torch_group_norm():
for prompt in prompts:
logger.info(f"Generating 🖼 : {prompt.prompt_description()}")
with ImageLoggingContext(
prompt=prompt,
model=model,
img_callback=img_callback,
):
logger.info(f"Generating {prompt.prompt_description()}")
seed_everything(prompt.seed)
model.tile_mode(prompt.tile_mode)

@ -98,6 +98,14 @@ def conditioning_to_img(conditioning):
return ToPILImage()(conditioning)
class IndentingFormatter(logging.Formatter):
def format(self, record):
s = super().format(record)
if _CURRENT_LOGGING_CONTEXT is not None:
s = f" {s}"
return s
def configure_logging(level="INFO"):
fmt = "%(message)s"
if level == "DEBUG":
@ -107,7 +115,10 @@ def configure_logging(level="INFO"):
"version": 1,
"disable_existing_loggers": True,
"formatters": {
"standard": {"format": fmt},
"standard": {
"format": fmt,
"class": "imaginairy.log_utils.IndentingFormatter",
},
},
"handlers": {
"default": {

@ -153,7 +153,7 @@ class ImaginePrompt:
def prompt_description(self):
return (
f'🖼 : "{self.prompt_text}" {self.width}x{self.height}px '
f'"{self.prompt_text}" {self.width}x{self.height}px '
f"seed:{self.seed} prompt-strength:{self.prompt_strength} steps:{self.steps} sampler-type:{self.sampler_type}"
)

Loading…
Cancel
Save