Skip to content

LoggingMixin

faststream.broker.core.mixins.LoggingMixin #

LoggingMixin(*args: Any, logger: Optional[Logger] = access_logger, log_level: int = logging.INFO, log_fmt: Optional[str] = '%(asctime)s %(levelname)s - %(message)s', **kwargs: Any)

A mixin class for logging.

METHOD DESCRIPTION
fmt

getter method for _fmt attribute

_get_log_context

returns a dictionary with log context information

_log

logs a message with optional log level, extra data, and exception info

Initialize the class.

PARAMETER DESCRIPTION
*args

Variable length argument list

TYPE: Any DEFAULT: ()

logger

Optional logger object

TYPE: Optional[Logger] DEFAULT: access_logger

log_level

Log level (default: logging.INFO)

TYPE: int DEFAULT: INFO

log_fmt

Log format (default: "%(asctime)s %(levelname)s - %(message)s")

TYPE: Optional[str] DEFAULT: '%(asctime)s %(levelname)s - %(message)s'

**kwargs

Arbitrary keyword arguments

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
None

None

Source code in faststream/broker/core/mixins.py
def __init__(
    self,
    *args: Any,
    logger: Optional[logging.Logger] = access_logger,
    log_level: int = logging.INFO,
    log_fmt: Optional[str] = "%(asctime)s %(levelname)s - %(message)s",
    **kwargs: Any,
) -> None:
    """Initialize the class.

    Args:
        *args: Variable length argument list
        logger: Optional logger object
        log_level: Log level (default: logging.INFO)
        log_fmt: Log format (default: "%(asctime)s %(levelname)s - %(message)s")
        **kwargs: Arbitrary keyword arguments

    Returns:
        None

    """
    self.logger = logger
    self.log_level = log_level
    self._fmt = log_fmt
    self._message_id_ln = 10

fmt property #

fmt: str

Getter method for _fmt attribute.

log_level instance-attribute #

log_level = log_level

logger instance-attribute #

logger = logger