Skip to content

logger

logger

LogLevel

Bases: str, Enum

Logical log levels for the CLI.

Includes a custom TRACE (more verbose than DEBUG) and QUIET (suppresses all output beyond CRITICAL).

Source code in source/src/justifactu/logger.py
class LogLevel(str, Enum):
    """
    Logical log levels for the CLI.

    Includes a custom TRACE (more verbose than DEBUG) and QUIET
    (suppresses all output beyond CRITICAL).
    """

    TRACE = "trace"
    DEBUG = "debug"
    INFO = "info"
    WARNING = "warning"
    ERROR = "error"
    QUIET = "quiet"

    @classmethod
    def parse(cls, value: Optional[str]) -> Optional["LogLevel"]:
        """Parse case-insensitively; returns None if value is falsy."""
        print("Executing function parse from LogLevel")
        if not value:
            return None
        norm = value.strip().lower()
        try:
            return cls(norm)
        except ValueError as exc:
            valid = ", ".join(v.value for v in cls)
            raise ValueError(f"Unknown log level '{value}'. Valid: {valid}") from exc

    @classmethod
    def get_default_log_level(cls) -> "LogLevel":
        return LogLevel.TRACE

    def to_logging_level(self) -> int:
        if self is LogLevel.TRACE:
            return 0
        if self is LogLevel.DEBUG:
            return logging.DEBUG
        if self is LogLevel.INFO:
            return logging.INFO
        if self is LogLevel.WARNING:
            return logging.WARNING
        if self is LogLevel.ERROR:
            return logging.ERROR
        if self is LogLevel.QUIET:
            return logging.CRITICAL + 10
        return LogLevel.get_default_log_level().to_logging_level()

parse classmethod

parse(value: Optional[str]) -> Optional[LogLevel]

Parse case-insensitively; returns None if value is falsy.

Source code in source/src/justifactu/logger.py
@classmethod
def parse(cls, value: Optional[str]) -> Optional["LogLevel"]:
    """Parse case-insensitively; returns None if value is falsy."""
    print("Executing function parse from LogLevel")
    if not value:
        return None
    norm = value.strip().lower()
    try:
        return cls(norm)
    except ValueError as exc:
        valid = ", ".join(v.value for v in cls)
        raise ValueError(f"Unknown log level '{value}'. Valid: {valid}") from exc

get_logger

get_logger(name: str) -> ExtendedLogger

Return a logger with trace() method available.

Source code in source/src/justifactu/logger.py
def get_logger(name: str) -> ExtendedLogger:
    """Return a logger with trace() method available."""
    return cast(ExtendedLogger, logging.getLogger(name))