Skip to content

Types and Enums

Type definitions, enumerations, and protocols exported from ezplog.

LogLevel

LogLevel maps log level names to their numeric priority and display colors. Use it when you need to compare levels programmatically or pass a typed level value.

from ezplog import LogLevel

# Access a level
level = LogLevel.INFO
print(level.label)   # "INFO"
print(level.no)      # 20

# Validate user input
if not LogLevel.is_valid_level("VERBOSE"):
    print("Unknown level")

# Get all available levels
print(LogLevel.get_all_levels())
# ['DEBUG', 'INFO', 'SUCCESS', 'WARNING', 'ERROR', 'CRITICAL']

Level Reference

Name Numeric Rich Style
DEBUG 10 cyan
INFO 20 blue
SUCCESS 25 bold green
WARNING 30 bold yellow
ERROR 40 bold red
CRITICAL 50 bold magenta on red

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.

Parameters:

Name Type Description Default
label str

Human-readable name of the log level

required
no int

Numeric level for comparison

required
fg str

Foreground color code

required
bg str

Background color code

required

get_attribute classmethod

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

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

Parameters:

Name Type Description Default
level str

The logging level name

required
attribute str

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

required

Returns:

Type Description
Any

The requested attribute value

Raises:

Type Description
ValueError

If the level or attribute is not found

get_label classmethod

get_label(level: str) -> str

Get the label for a given log level.

Parameters:

Name Type Description Default
level str

The logging level name

required

Returns:

Type Description
str

The label for the log level

get_no classmethod

get_no(level: str) -> int

Get the numeric level for a given log level.

Parameters:

Name Type Description Default
level str

The logging level name

required

Returns:

Type Description
int

The numeric level

get_fgcolor classmethod

get_fgcolor(level: str) -> str

Get the foreground color for a given log level.

Parameters:

Name Type Description Default
level str

The logging level name

required

Returns:

Type Description
str

The foreground color code

get_bgcolor classmethod

get_bgcolor(level: str) -> str

Get the background color for a given log level.

Parameters:

Name Type Description Default
level str

The logging level name

required

Returns:

Type Description
str

The background color code

is_valid_level classmethod

is_valid_level(level: str) -> bool

Check if a given level is valid.

Parameters:

Name Type Description Default
level str

The logging level name to check

required

Returns:

Type Description
bool

True if the level is valid, False otherwise

get_all_levels classmethod

get_all_levels() -> list[str]

Get all available log levels.

Returns:

Type Description
list[str]

List of all available log level names

get_rich_style

get_rich_style() -> str

Get the Rich style string for this log level.

Returns:

Type Description
str

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

options: show_source: false show_root_heading: true show_root_full_path: false show_symbol_type_heading: true members_order: source show_if_no_docstring: false show_signature_annotations: true separate_signature: true docstring_style: google docstring_section_style: table


Pattern

Pattern provides semantic meaning beyond log levels. Each pattern maps to a fixed Rich color string used by EzPrinter.print_pattern().

from ezplog import Ezpl, Pattern

ezpl = Ezpl()
printer = ezpl.get_printer()

# Use a pattern enum directly
printer.print_pattern(Pattern.TIP, "Enable caching for better performance")
printer.print_pattern(Pattern.INSTALL, "Installing dependency: requests")

Pattern Reference

Name Output label Color
SUCCESS SUCCESS bright_green
ERROR ERROR bright_red
WARN WARN bright_yellow
TIP TIP bright_magenta
DEBUG DEBUG dim white
INFO INFO bright_blue
SYSTEM SYSTEM bright_blue
INSTALL INSTALL bright_green
DETECT DETECT bright_blue
CONFIG CONFIG bright_green
DEPS DEPS bright_cyan

Pattern

Bases: Enum

Contextual patterns for console output.

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

options: show_source: false show_root_heading: true show_root_full_path: false show_symbol_type_heading: true members_order: source show_if_no_docstring: false show_signature_annotations: true separate_signature: true docstring_style: google docstring_section_style: table


Pattern Color Utilities

get_pattern_color

get_pattern_color(pattern: Pattern) -> str

Get the Rich color style for a pattern.

Parameters:

Name Type Description Default
pattern Pattern

The pattern to get the color for

required

Returns:

Type Description
str

Rich color style string

options: show_source: false show_root_heading: true show_signature_annotations: true separate_signature: true docstring_style: google docstring_section_style: table

get_pattern_color_by_name

get_pattern_color_by_name(pattern_name: str) -> str

Get the Rich color style for a pattern by name.

Parameters:

Name Type Description Default
pattern_name str

The pattern name (case-insensitive)

required

Returns:

Type Description
str

Rich color style string

options: show_source: false show_root_heading: true show_signature_annotations: true separate_signature: true docstring_style: google docstring_section_style: table


Protocols

Protocols allow type-safe use of ezplog components without importing the concrete classes. Useful in library code or when injecting custom implementations.

from ezplog import PrinterProtocol, LoggerProtocol

def setup_reporting(printer: PrinterProtocol, logger: LoggerProtocol) -> None:
    printer.info("Report started")
    logger.info("Report started")

PrinterProtocol

Bases: Protocol

Protocol defining the interface for printer implementations.

All printer implementations must conform to this protocol to ensure consistent API and type safety.

Required Methods: - Logging methods: info(), debug(), success(), warning(), warn(), error(), critical() - Pattern methods: tip(), system(), install(), detect(), config(), deps() - Enhanced methods: print_pattern(), print_json() - Utility methods: set_level(), log() - Indentation methods: add_indent(), del_indent(), reset_indent(), manage_indent()

Required Properties: - wizard: Access to RichWizard instance for advanced features

level property

level: str

Get the current logging level.

wizard property

wizard: Any

Get RichWizard instance for advanced features.

info

info(message: Any) -> None

Log an info message.

debug

debug(message: Any) -> None

Log a debug message.

success

success(message: Any) -> None

Log a success message.

warning

warning(message: Any) -> None

Log a warning message.

warn

warn(message: Any) -> None

Alias for warning(). Log a warning message.

error

error(message: Any) -> None

Log an error message.

critical

critical(message: Any) -> None

Log a critical message.

tip

tip(message: Any) -> None

Display a tip message.

system

system(message: Any) -> None

Display a system message.

install

install(message: Any) -> None

Display an installation message.

detect

detect(message: Any) -> None

Display a detection message.

config

config(message: Any) -> None

Display a configuration message.

deps

deps(message: Any) -> None

Display a dependencies message.

print_pattern

print_pattern(pattern: str | Pattern, message: Any, level: str = 'INFO') -> None

Display a message with pattern format.

print_json

print_json(data: str | dict | list, title: str | None = None, indent: int | None = None, highlight: bool = True) -> None

Display JSON data in formatted way.

set_level

set_level(level: str) -> None

Set the logging level.

log

log(level: str, message: Any) -> None

Log a message with specified level.

add_indent

add_indent() -> None

Increase indentation level.

del_indent

del_indent() -> None

Decrease indentation level.

reset_indent

reset_indent() -> None

Reset indentation to zero.

manage_indent

manage_indent() -> AbstractContextManager[None]

Context manager for temporary indentation.

options: show_source: false show_root_heading: true show_root_full_path: false show_symbol_type_heading: true members_order: source show_if_no_docstring: false show_signature_annotations: true separate_signature: true docstring_style: google docstring_section_style: table

LoggerProtocol

Bases: Protocol

Protocol defining the interface for logger implementations.

All logger implementations must conform to this protocol to ensure consistent API and type safety.

Required Methods: - Logging methods: info(), debug(), success(), warning(), warn(), error(), critical(), trace(), bind() - Utility methods: set_level(), log(), add_separator() - Getter methods: get_logger(), get_log_file()

Note: This protocol is designed to be compatible with loguru.Logger while allowing custom implementations.

level property

level: str

Get the current logging level.

trace

trace(message: Any, *args, **kwargs) -> None

Log a trace message.

debug

debug(message: Any, *args, **kwargs) -> None

Log a debug message.

info

info(message: Any, *args, **kwargs) -> None

Log an info message.

success

success(message: Any, *args, **kwargs) -> None

Log a success message.

warning

warning(message: Any, *args, **kwargs) -> None

Log a warning message.

warn

warn(message: Any, *args, **kwargs) -> None

Alias for warning(). Log a warning message.

error

error(message: Any, *args, **kwargs) -> None

Log an error message.

critical

critical(message: Any, *args, **kwargs) -> None

Log a critical message.

exception

exception(message: Any, *args, **kwargs) -> None

Log an exception with traceback.

bind

bind(**kwargs: Any) -> Any

Bind context variables to the logger.

opt

opt(**kwargs: Any) -> Any

Configure logger options.

patch

patch(patcher: Any) -> Any

Patch log records.

set_level

set_level(level: str) -> None

Set the logging level.

log

log(level: str, message: Any) -> None

Log a message with specified level.

add_separator

add_separator() -> None

Add a session separator to the log file.

get_log_file

get_log_file() -> Path

Get the current log file path.

close

close() -> None

Close the logger and release resources.

options: show_source: false show_root_heading: true show_root_full_path: false show_symbol_type_heading: true members_order: source show_if_no_docstring: false show_signature_annotations: true separate_signature: true docstring_style: google docstring_section_style: table


Type Aliases

from ezplog import Printer, Logger
Alias Resolves to Use
Printer EzPrinter Type annotation for printer variables
Logger EzLogger Type annotation for logger variables
from ezplog import Ezpl, Printer, Logger

ezpl = Ezpl()
printer: Printer = ezpl.get_printer()
logger: Logger = ezpl.get_logger()