Skip to content

Types and Enums

Type definitions and enumerations.

LogLevel

Log level enumeration with colors and styles.

LogLevel

LogLevel(label: str, no: int, fg: str, bg: str)

Bases: Enum

LogLevel is an enumeration representing different logging levels with associated names, numeric levels, and colorimetric configurations.

Attributes: * label: Human-readable name of the log level * no: Numeric level for comparison * fg: Foreground color code * bg: Background color code

Levels: * DEBUG: Debugging messages (lowest priority) * INFO: Informational messages * SUCCESS: Success messages * WARNING: Warning messages * ERROR: Error messages * CRITICAL: Critical messages (highest priority)

Initialize a LogLevel instance.

PARAMETER DESCRIPTION
label

Human-readable name of the log level

TYPE: str

no

Numeric level for comparison

TYPE: int

fg

Foreground color code

TYPE: str

bg

Background color code

TYPE: str

Source code in src/ezpl/types/enums/log_level.py
def __init__(self, label: str, no: int, fg: str, bg: str) -> None:
    """
    Initialize a LogLevel instance.

    Args:
        label: Human-readable name of the log level
        no: Numeric level for comparison
        fg: Foreground color code
        bg: Background color code
    """
    self.label = label
    self.no = no
    self.fg = fg
    self.bg = bg

get_attribute classmethod

get_attribute(level: str, attribute: str) -> Any

Returns the specified attribute (label, no, fg, bg) for a given logging level.

PARAMETER DESCRIPTION
level

The logging level name

TYPE: str

attribute

The attribute to retrieve ('label', 'no', 'fg', 'bg')

TYPE: str

RETURNS DESCRIPTION
Any

The requested attribute value

RAISES DESCRIPTION
ValueError

If the level or attribute is not found

Source code in src/ezpl/types/enums/log_level.py
@classmethod
def get_attribute(cls, level: str, attribute: str) -> Any:
    """
    Returns the specified attribute (label, no, fg, bg) for a given logging level.

    Args:
        level: The logging level name
        attribute: The attribute to retrieve ('label', 'no', 'fg', 'bg')

    Returns:
        The requested attribute value

    Raises:
        ValueError: If the level or attribute is not found
    """
    try:
        lvl = cls[level.upper()]
        return getattr(lvl, attribute)
    except KeyError as e:
        raise ValidationError(f"Unknown level '{level}'", "level", level) from e
    except AttributeError as e:
        raise ValidationError(
            f"Invalid attribute '{attribute}'", "attribute", attribute
        ) from e

get_label classmethod

get_label(level: str) -> str

Get the label for a given log level.

PARAMETER DESCRIPTION
level

The logging level name

TYPE: str

RETURNS DESCRIPTION
str

The label for the log level

Source code in src/ezpl/types/enums/log_level.py
@classmethod
def get_label(cls, level: str) -> str:
    """
    Get the label for a given log level.

    Args:
        level: The logging level name

    Returns:
        The label for the log level
    """
    return cast(str, cls.get_attribute(level, "label"))

get_no classmethod

get_no(level: str) -> int

Get the numeric level for a given log level.

PARAMETER DESCRIPTION
level

The logging level name

TYPE: str

RETURNS DESCRIPTION
int

The numeric level

Source code in src/ezpl/types/enums/log_level.py
@classmethod
def get_no(cls, level: str) -> int:
    """
    Get the numeric level for a given log level.

    Args:
        level: The logging level name

    Returns:
        The numeric level
    """
    return cast(int, cls.get_attribute(level, "no"))

get_fgcolor classmethod

get_fgcolor(level: str) -> str

Get the foreground color for a given log level.

PARAMETER DESCRIPTION
level

The logging level name

TYPE: str

RETURNS DESCRIPTION
str

The foreground color code

Source code in src/ezpl/types/enums/log_level.py
@classmethod
def get_fgcolor(cls, level: str) -> str:
    """
    Get the foreground color for a given log level.

    Args:
        level: The logging level name

    Returns:
        The foreground color code
    """
    return cast(str, cls.get_attribute(level, "fg"))

get_bgcolor classmethod

get_bgcolor(level: str) -> str

Get the background color for a given log level.

PARAMETER DESCRIPTION
level

The logging level name

TYPE: str

RETURNS DESCRIPTION
str

The background color code

Source code in src/ezpl/types/enums/log_level.py
@classmethod
def get_bgcolor(cls, level: str) -> str:
    """
    Get the background color for a given log level.

    Args:
        level: The logging level name

    Returns:
        The background color code
    """
    return cast(str, cls.get_attribute(level, "bg"))

is_valid_level classmethod

is_valid_level(level: str) -> bool

Check if a given level is valid.

PARAMETER DESCRIPTION
level

The logging level name to check

TYPE: str

RETURNS DESCRIPTION
bool

True if the level is valid, False otherwise

Source code in src/ezpl/types/enums/log_level.py
@classmethod
def is_valid_level(cls, level: str) -> bool:
    """
    Check if a given level is valid.

    Args:
        level: The logging level name to check

    Returns:
        True if the level is valid, False otherwise
    """
    try:
        cls[level.upper()]
        return True
    except KeyError:
        return False

get_all_levels classmethod

get_all_levels() -> list[str]

Get all available log levels.

RETURNS DESCRIPTION
list[str]

List of all available log level names

Source code in src/ezpl/types/enums/log_level.py
@classmethod
def get_all_levels(cls) -> list[str]:
    """
    Get all available log levels.

    Returns:
        List of all available log level names
    """
    return [level.name for level in cls]

get_rich_style

get_rich_style() -> str

Get the Rich style string for this log level.

RETURNS DESCRIPTION
str

Rich style string (e.g., "bold red", "cyan", etc.)

Source code in src/ezpl/types/enums/log_level.py
def get_rich_style(self) -> str:
    """
    Get the Rich style string for this log level.

    Returns:
        Rich style string (e.g., "bold red", "cyan", etc.)
    """
    styles = {
        "DEBUG": "cyan",
        "INFO": "blue",
        "SUCCESS": "bold green",
        "WARNING": "bold yellow",
        "ERROR": "bold red",
        "CRITICAL": "bold magenta on red",
    }
    return styles.get(self.name, "")

Pattern

Contextual pattern enumeration.

Pattern

Bases: Enum

Contextual patterns for console output.

Patterns provide semantic meaning beyond log levels, allowing for more expressive and contextual logging.

Pattern Colors

Pattern color mapping utilities.

get_pattern_color

get_pattern_color(pattern: Pattern) -> str

Get the Rich color style for a pattern.

PARAMETER DESCRIPTION
pattern

The pattern to get the color for

TYPE: Pattern

RETURNS DESCRIPTION
str

Rich color style string

get_pattern_color_by_name

get_pattern_color_by_name(pattern_name: str) -> str

Get the Rich color style for a pattern by name.

PARAMETER DESCRIPTION
pattern_name

The pattern name (case-insensitive)

TYPE: str

RETURNS DESCRIPTION
str

Rich color style string

PATTERN_COLORS module-attribute

PATTERN_COLORS: dict[Pattern, str] = {SUCCESS: 'bright_green', ERROR: 'bright_red', WARN: 'bright_yellow', TIP: 'bright_magenta', DEBUG: 'dim white', INFO: 'bright_blue', SYSTEM: 'bright_blue', INSTALL: 'bright_green', DETECT: 'bright_blue', CONFIG: 'bright_green', DEPS: 'bright_cyan'}