mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
AutoGPT: Remove color codes in file log output
This commit is contained in:
@@ -57,18 +57,22 @@ def configure_logging(config: Config, log_dir: Path = LOG_DIR) -> None:
|
||||
# INFO log file handler
|
||||
activity_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 handler
|
||||
debug_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 handler
|
||||
error_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 logger
|
||||
logging.basicConfig(
|
||||
|
||||
@@ -8,6 +8,10 @@ from .utils import remove_color_codes
|
||||
|
||||
|
||||
class 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 string
|
||||
if not hasattr(record, "msg"):
|
||||
@@ -29,4 +33,7 @@ class AutoGptFormatter(FancyConsoleFormatter):
|
||||
# Make sure record.title is set, and padded with a space if not empty
|
||||
record.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)
|
||||
|
||||
Reference in New Issue
Block a user