diff options
Diffstat (limited to 'autogpt/logs/formatters.py')
-rw-r--r-- | autogpt/logs/formatters.py | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/autogpt/logs/formatters.py b/autogpt/logs/formatters.py deleted file mode 100644 index 50e7c3333..000000000 --- a/autogpt/logs/formatters.py +++ /dev/null @@ -1,41 +0,0 @@ -import logging -import re - -from colorama import Style - - -class AutoGptFormatter(logging.Formatter): - """ - Allows to handle custom placeholders 'title_color' and 'message_no_color'. - To use this formatter, make sure to pass 'color', 'title' as log extras. - """ - - def format(self, record: logging.LogRecord) -> str: - if hasattr(record, "color"): - record.title_color = ( - getattr(record, "color") - + getattr(record, "title", "") - + " " - + Style.RESET_ALL - ) - else: - record.title_color = getattr(record, "title", "") - - # Add this line to set 'title' to an empty string if it doesn't exist - record.title = getattr(record, "title", "") - - if hasattr(record, "msg"): - record.message_no_color = remove_color_codes(getattr(record, "msg")) - else: - record.message_no_color = "" - return super().format(record) - - -def remove_color_codes(s: str) -> str: - ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])") - return ansi_escape.sub("", s) - - -class JsonFormatter(logging.Formatter): - def format(self, record: logging.LogRecord): - return record.msg |