Skip to content

ExtendedFilter

faststream.log.logging.ExtendedFilter #

ExtendedFilter(default_context, message_id_ln, name='')

Bases: Filter

Source code in faststream/log/logging.py
def __init__(
    self,
    default_context: Mapping[str, str],
    message_id_ln: int,
    name: str = "",
) -> None:
    self.default_context = default_context
    self.message_id_ln = message_id_ln
    super().__init__(name)

default_context instance-attribute #

default_context = default_context

message_id_ln instance-attribute #

message_id_ln = message_id_ln

filter #

filter(record)
Source code in faststream/log/logging.py
def filter(self, record: LogRecord) -> bool:
    if is_suitable := super().filter(record):
        log_context: Mapping[str, str] = context.get_local(
            "log_context", self.default_context
        )

        for k, v in log_context.items():
            value = getattr(record, k, v)
            setattr(record, k, value)

        record.message_id = getattr(record, "message_id", "")[: self.message_id_ln]

    return is_suitable