AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
AutoGPT: Remove color codes in file log output
Reinier van der Leer5acb5ad9b787
diff --git a/autogpts/autogpt/autogpt/logs/config.py b/autogpts/autogpt/autogpt/logs/config.pyindex ce278f0269..dc3a2578a7 100644--- a/autogpts/autogpt/autogpt/logs/config.py+++ b/autogpts/autogpt/autogpt/logs/config.py@@ -57,18 +57,22 @@ def configure_logging(config: Config, log_dir: Path = LOG_DIR) -> None:# INFO log file handleractivity_log_handler = logging.FileHandler(log_dir / LOG_FILE, "a", "utf-8")activity_log_handler.setLevel(logging.INFO)- activity_log_handler.setFormatter(AutoGptFormatter(SIMPLE_LOG_FORMAT))+ activity_log_handler.setFormatter(+ AutoGptFormatter(SIMPLE_LOG_FORMAT, no_color=True)+ )if config.debug_mode:# DEBUG log file handlerdebug_log_handler = logging.FileHandler(log_dir / DEBUG_LOG_FILE, "a", "utf-8")debug_log_handler.setLevel(logging.DEBUG)- debug_log_handler.setFormatter(AutoGptFormatter(DEBUG_LOG_FORMAT))+ debug_log_handler.setFormatter(+ AutoGptFormatter(DEBUG_LOG_FORMAT, no_color=True)+ )# ERROR log file handlererror_log_handler = logging.FileHandler(log_dir / ERROR_LOG_FILE, "a", "utf-8")error_log_handler.setLevel(logging.ERROR)- error_log_handler.setFormatter(AutoGptFormatter(DEBUG_LOG_FORMAT))+ error_log_handler.setFormatter(AutoGptFormatter(DEBUG_LOG_FORMAT, no_color=True))# Configure the root loggerlogging.basicConfig(diff --git a/autogpts/autogpt/autogpt/logs/formatters.py b/autogpts/autogpt/autogpt/logs/formatters.pyindex 6166b57173..4930d3c733 100644--- a/autogpts/autogpt/autogpt/logs/formatters.py+++ b/autogpts/autogpt/autogpt/logs/formatters.py@@ -8,6 +8,10 @@ from .utils import remove_color_codesclass AutoGptFormatter(FancyConsoleFormatter):+ def __init__(self, *args, no_color: bool = False, **kwargs):+ super().__init__(*args, **kwargs)+ self.no_color = no_color+def format(self, record: logging.LogRecord) -> str:# Make sure `msg` is a stringif not hasattr(record, "msg"):@@ -29,4 +33,7 @@ class AutoGptFormatter(FancyConsoleFormatter):# Make sure record.title is set, and padded with a space if not emptyrecord.title = f"{title} " if title else ""- return super().format(record)+ if self.no_color:+ return remove_color_codes(super().format(record))+ else:+ return super().format(record)