The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. The fastest local inference engine in the world.
Add colored logs (#14036)
Talmaj63bcaec5d14c
diff --git a/app/logger.py b/app/logger.pyindex 3d26d98fe..bde815822 100644--- a/app/logger.py+++ b/app/logger.py@@ -5,6 +5,40 @@ import loggingimport sysimport threading+ANSI_NAMED_COLORS = {+ 'black': '\033[30m',+ 'red': '\033[31m',+ 'green': '\033[32m',+ 'yellow': '\033[33m',+ 'blue': '\033[34m',+ 'magenta': '\033[35m',+ 'cyan': '\033[36m',+ 'white': '\033[37m',+}++ANSI_LEVEL_COLORS = {+ 'DEBUG': ANSI_NAMED_COLORS['cyan'],+ 'INFO': ANSI_NAMED_COLORS['green'],+ 'WARNING': ANSI_NAMED_COLORS['yellow'],+ 'ERROR': ANSI_NAMED_COLORS['red'],+ 'CRITICAL': ANSI_NAMED_COLORS['magenta'],+}++ANSI_RESET = '\033[0m'+ANSI_BOLD = '\033[1m'+++class ColoredFormatter(logging.Formatter):+ def format(self, record):+ color = ANSI_LEVEL_COLORS.get(record.levelname, '')+ bold = ANSI_BOLD if record.levelno >= logging.WARNING else ''+ level_tag = f"{bold}{color}[{record.levelname}]{ANSI_RESET} "+ message = super().format(record)+ line_color = ANSI_NAMED_COLORS.get(getattr(record, 'color', ''), '')+ if line_color:+ return f"{level_tag}{line_color}{message}{ANSI_RESET}"+ return level_tag + message+logs = Nonestdout_interceptor = Nonestderr_interceptor = None@@ -68,8 +102,10 @@ def setup_logger(log_level: str = 'INFO', capacity: int = 300, use_stdout: boollogger = logging.getLogger()logger.setLevel(log_level)+ formatter = ColoredFormatter("%(message)s")+stream_handler = logging.StreamHandler()- stream_handler.setFormatter(logging.Formatter("%(message)s"))+ stream_handler.setFormatter(formatter)if use_stdout:# Only errors and critical to stderr@@ -77,7 +113,7 @@ def setup_logger(log_level: str = 'INFO', capacity: int = 300, use_stdout: bool# Lesser to stdoutstdout_handler = logging.StreamHandler(sys.stdout)- stdout_handler.setFormatter(logging.Formatter("%(message)s"))+ stdout_handler.setFormatter(formatter)stdout_handler.addFilter(lambda record: record.levelno < logging.ERROR)logger.addHandler(stdout_handler)diff --git a/main.py b/main.pyindex f23074942..26d523c30 100644--- a/main.py+++ b/main.py@@ -344,9 +344,9 @@ def prompt_worker(q, server_instance):# Log Time in a more readable way after 10 minutesif execution_time > 600:execution_time = time.strftime("%H:%M:%S", time.gmtime(execution_time))- logging.info(f"Prompt executed in {execution_time}")+ logging.info(f"Prompt executed in {execution_time}", extra={'color': 'green'})else:- logging.info("Prompt executed in {:.2f} seconds".format(execution_time))+ logging.info("Prompt executed in {:.2f} seconds".format(execution_time), extra={'color': 'green'})if not asset_seeder.is_disabled():paths = _collect_output_absolute_paths(e.history_result)