Skip to content

truncate_logging_filter

TruncateLoggingFilter

Bases: Filter

Source code in griptape/configs/logging/truncate_logging_filter.py
@define
class TruncateLoggingFilter(logging.Filter):
    max_log_length: int = field(default=1000, kw_only=True)

    def filter(self, record: Any) -> bool:
        message = record.getMessage()

        if len(message) > self.max_log_length:
            record.msg = f"{message[:self.max_log_length]}... [{len(message) - self.max_log_length} more characters]"
            record.args = ()
        return True

max_log_length: int = field(default=1000, kw_only=True) class-attribute instance-attribute

filter(record)

Source code in griptape/configs/logging/truncate_logging_filter.py
def filter(self, record: Any) -> bool:
    message = record.getMessage()

    if len(message) > self.max_log_length:
        record.msg = f"{message[:self.max_log_length]}... [{len(message) - self.max_log_length} more characters]"
        record.args = ()
    return True