Skip to content

EzPrinter

Rich console printer handler.

šŸ” API

EzPrinter

EzPrinter(level: str = 'INFO', indent_step: int = 3, indent_symbol: str = '>', base_indent_symbol: str = '~')

Bases: LoggingHandler, IndentationManager

Console printer handler with advanced formatting and indentation support using Rich.

This handler provides console-based logging with: - Color-coded log levels using Rich - Indentation management - Robust character handling (Rich handles special characters automatically) - Context manager support - Pattern-based logging (SUCCESS, ERROR, WARN, TIP, etc.) - Access to RichWizard for advanced display features

Initialize the console printer handler.

Parameters:

Name Type Description Default
level str

The desired logging level

'INFO'
indent_step int

Number of spaces for each indentation level

3
indent_symbol str

Symbol for indentation levels

'>'
base_indent_symbol str

Symbol for the base indentation

'~'

Raises:

Type Description
ValidationError

If the provided level is invalid

Attributes

level property

level: str

Return the current logging level.

level_manually_set property

level_manually_set: bool

Return whether level was set manually at runtime.

indent_step property

indent_step: int

Return the configured indentation step.

indent_symbol property

indent_symbol: str

Return the configured indentation symbol.

base_indent_symbol property

base_indent_symbol: str

Return the configured base indentation symbol.

wizard property

wizard: RichWizard

Get the Rich Wizard instance for advanced display features.

Returns:

Type Description
RichWizard

RichWizard instance for panels, tables, JSON, etc.

Example

printer.wizard.success_panel("Success", "Operation completed") printer.wizard.status_table("Status", data) printer.wizard.dependency_table({"tool": "1.0.0"})

Functions

mark_level_as_configured

mark_level_as_configured() -> None

Mark the current level as coming from configuration (not manual set).

set_level

set_level(level: str) -> None

Set the logging level.

Parameters:

Name Type Description Default
level str

The desired logging level

required

Raises:

Type Description
ValidationError

If the provided level is invalid

log

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

Log a message with the specified level.

Parameters:

Name Type Description Default
level str

The log level

required
message Any

The message to log (any type, will be safely converted to string)

required

Raises:

Type Description
ValidationError

If the level is invalid

info

info(message: Any) -> None

Log an informational message with pattern format.

debug

debug(message: Any) -> None

Log a debug message with pattern format.

success

success(message: Any) -> None

Log a success message with pattern format.

warning

warning(message: Any) -> None

Log a warning message with pattern format.

error

error(message: Any) -> None

Log an error message with pattern format.

critical

critical(message: Any) -> None

Log a critical message with pattern format.

tip

tip(message: Any) -> None

Display a tip message with pattern format.

system

system(message: Any) -> None

Display a system message with pattern format.

install

install(message: Any) -> None

Display an installation message with pattern format.

detect

detect(message: Any) -> None

Display a detection message with pattern format.

config

config(message: Any) -> None

Display a configuration message with pattern format.

deps

deps(message: Any) -> None

Display a dependencies message with pattern format.

print_pattern

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

Display a message with pattern format: • PATTERN :: message

Parameters:

Name Type Description Default
pattern str | Pattern

Pattern name (string) or Pattern enum

required
message Any

Message to display

required
level str

Log level for filtering (default: INFO)

'INFO'

get_indent

get_indent() -> str

Get the current indentation string.

Returns:

Type Description
str

The current indentation string

add_indent

add_indent() -> None

Increase the indentation level by one (with maximum limit).

del_indent

del_indent() -> None

Decrease the indentation level by one, ensuring it doesn't go below zero.

reset_indent

reset_indent() -> None

Reset the indentation level to zero.

manage_indent

manage_indent() -> Generator[None, None, None]

Context manager for temporary indentation.

Yields:

Type Description
None

None

print_table

print_table(data: list[dict[str, Any]], title: str | None = None) -> None

Display a table using Rich (delegates to RichWizard).

Parameters:

Name Type Description Default
data list[dict[str, Any]]

List of dictionaries representing table rows

required
title str | None

Optional table title

None

print_panel

print_panel(content: str, title: str | None = None, style: str = 'blue') -> None

Display a panel using Rich (delegates to RichWizard).

Parameters:

Name Type Description Default
content str

Panel content

required
title str | None

Optional panel title

None
style str

Panel style (Rich style string, used as border_style)

'blue'

print_progress

print_progress(*args, **kwargs) -> None

Display a progress bar using Rich.

Note: This is a placeholder. For full progress functionality, users should use Rich's Progress context manager directly.

print_json

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

Display JSON data in a formatted and syntax-highlighted way using Rich (delegates to RichWizard).

Parameters:

Name Type Description Default
data str | dict | list

JSON data to display (dict, list, or JSON string)

required
title str | None

Optional title for the JSON display

None
indent int | None

Number of spaces for indentation (default: 2)

None
highlight bool

Whether to enable syntax highlighting (default: True)

True

Examples:

>>> printer.print_json({"name": "Alice", "age": 30})
>>> printer.print_json('{"key": "value"}', title="Config")
>>> printer.print_json([1, 2, 3], indent=4)