diff --git a/app/logger.py b/app/logger.py index d23822958..b36eb4571 100644 --- a/app/logger.py +++ b/app/logger.py @@ -5,13 +5,25 @@ import logging import sys import threading -ANSI_LEVEL_COLORS = { - 'DEBUG': '\033[36m', # cyan - 'INFO': '\033[32m', # green - 'WARNING': '\033[33m', # yellow - 'ERROR': '\033[31m', # red - 'CRITICAL': '\033[35m', # magenta +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' @@ -21,7 +33,11 @@ class ColoredFormatter(logging.Formatter): 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} " - return level_tag + super().format(record) + 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 = None stdout_interceptor = None diff --git a/main.py b/main.py index 15a6460b2..521ad7004 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 minutes if 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)