Skip to content

_loggers

Define loggers for a logging dictConfig.

BaseLoggingConfig dataclass

Bases: ABC

Abstract base class for a full logging config dict.

Source code in src/red_logging/config_classes/base/_bases.py
@dataclass
class BaseLoggingConfig(ABC):
    """Abstract base class for a full logging config dict."""

    @abstractmethod
    def get_configdict(self) -> None:
        pass

LoggerConfig dataclass

Bases: BaseLoggingConfig

Define a logging Logger.

Parameters:

Name Type Description Default
name str

The name of the logger.

required
level str

The level of log messages this logger should show (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL).

required
handlers list[str]

List of handler names this logger should use. These handlers must exist in the logging dictConfig.

required
propagate bool

If True, messages will be propagated up/down to the root logger.

False
Source code in src/red_logging/config_classes/loggers/_loggers.py
@dataclass
class LoggerConfig(BaseLoggingConfig):
    """Define a logging Logger.

    Params:
        name (str): The name of the logger.
        level (str): The level of log messages this logger should show (NOTSET, DEBUG, INFO, WARNING, ERROR, CRITICAL).
        handlers (list[str]): List of handler names this logger should use. These handlers must exist in the logging dictConfig.
        propagate (bool): If `True`, messages will be propagated up/down to the root logger.
    """

    name: str
    level: str
    handlers: list[str]
    propagate: bool = False

    def get_configdict(self) -> dict:
        """Return a dict representation of the logger described by this class."""
        logger_dict: dict[str, dict[str, t.Any]] = {
            self.name: {
                "level": self.level,
                "handlers": self.handlers,
                "propagate": self.propagate,
            }
        }
        return logger_dict

get_configdict()

Return a dict representation of the logger described by this class.

Source code in src/red_logging/config_classes/loggers/_loggers.py
def get_configdict(self) -> dict:
    """Return a dict representation of the logger described by this class."""
    logger_dict: dict[str, dict[str, t.Any]] = {
        self.name: {
            "level": self.level,
            "handlers": self.handlers,
            "propagate": self.propagate,
        }
    }
    return logger_dict