Skip to content

logging

__all__ = ['LoggingConfig', 'TruncateLoggingFilter', 'NewlineLoggingFilter'] module-attribute

LoggingConfig

Source code in griptape/configs/logging/logging_config.py
@define
class LoggingConfig:
    logger_name: str = field(default="griptape", kw_only=True)

    def __attrs_post_init__(self) -> None:
        logger = logging.getLogger(self.logger_name)
        logger.setLevel(logging.INFO)
        logger.propagate = False
        logger.addHandler(RichHandler(show_time=True, show_path=False))

logger_name: str = field(default='griptape', kw_only=True) class-attribute instance-attribute

__attrs_post_init__()

Source code in griptape/configs/logging/logging_config.py
def __attrs_post_init__(self) -> None:
    logger = logging.getLogger(self.logger_name)
    logger.setLevel(logging.INFO)
    logger.propagate = False
    logger.addHandler(RichHandler(show_time=True, show_path=False))

NewlineLoggingFilter

Bases: Filter

Source code in griptape/configs/logging/newline_logging_filter.py
@define
class NewlineLoggingFilter(logging.Filter):
    replace_str: str = field(default=" ", kw_only=True)

    def filter(self, record: Any) -> bool:
        record.msg = record.msg.replace("\n", self.replace_str)
        return True

replace_str: str = field(default=' ', kw_only=True) class-attribute instance-attribute

filter(record)

Source code in griptape/configs/logging/newline_logging_filter.py
def filter(self, record: Any) -> bool:
    record.msg = record.msg.replace("\n", self.replace_str)
    return True

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