EzPrinter¶
Rich-based console output handler with pattern formatting, indentation management, and access to advanced display features.
Overview¶
EzPrinter (alias: Printer) renders all console output via Rich. Every message uses the format • PATTERN :: message, where the pattern determines the color. Indentation is inserted between :: and the message text.
EzPrinter is normally obtained through Ezpl.get_printer(). You can also use it standalone or inject a custom subclass via Ezpl.set_printer_class().
EzPrinter does not write to files. For file output, use EzLogger.
Usage¶
from ezplog import Ezpl
ezpl = Ezpl()
printer = ezpl.get_printer()
# Standard log levels
printer.debug("Entering handler")
printer.info("Request received")
printer.success("Order processed")
printer.warning("Response time above threshold")
printer.error("Database unavailable")
printer.critical("Out of memory — halting")
# Semantic patterns
printer.tip("Enable caching to improve performance")
printer.system("Detected OS: Linux")
printer.install("Installing requests==2.31.0")
printer.detect("Found .env at /home/user/project")
printer.config("Using profile: production")
printer.deps("Checking numpy >= 1.26")
# Generic pattern dispatch
from ezplog import Pattern
printer.print_pattern(Pattern.SUCCESS, "Build passed", level="INFO")
# JSON display
printer.print_json({"host": "localhost", "port": 5432}, title="DB config")
# Table display
printer.print_table(
[{"Package": "rich", "Version": "13.7"}, {"Package": "loguru", "Version": "0.7"}],
title="Installed packages",
)
# Panel display
printer.print_panel("All systems operational.", title="Status", style="green")
# Access RichWizard for advanced features
printer.wizard.success_panel("Build complete", "4 targets built in 2.3s")
printer.wizard.table([{"File": "main.py", "Lines": 120}], title="Changed files")
Indentation¶
from ezplog import Ezpl
ezpl = Ezpl()
printer = ezpl.get_printer()
printer.info("Starting migration")
with printer.manage_indent(): # enters indent level 1
printer.info("Applying schema v3")
with printer.manage_indent(): # enters indent level 2
printer.success("Table users updated")
printer.success("Table orders updated")
printer.info("Verifying integrity")
printer.success("Migration complete")
The context manager is re-entrant: nesting manage_indent() calls stacks indentation levels up to a maximum of 10.
Class Reference¶
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 |
level_manually_set
property
¶
Return whether level was set manually at runtime.
base_indent_symbol
property
¶
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"})
mark_level_as_configured
¶
Mark the current level as coming from configuration (not manual set).
set_level
¶
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 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 |
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 the current indentation string.
Returns:
| Type | Description |
|---|---|
str
|
The current indentation string |
del_indent
¶
Decrease the indentation level by one, ensuring it doesn't go below zero.
manage_indent
¶
Context manager for temporary indentation.
Yields:
| Type | Description |
|---|---|
None
|
None |
print_table
¶
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
¶
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
¶
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:
options: show_source: false show_root_heading: true show_root_full_path: false show_symbol_type_heading: true show_symbol_type_toc: true members_order: source group_by_category: true show_category_heading: true show_if_no_docstring: false show_signature_annotations: true separate_signature: true signature_crossrefs: true merge_init_into_class: true docstring_style: google docstring_section_style: table
Pattern Reference¶
| Method | Pattern | Color |
|---|---|---|
info() |
INFO |
bright_blue |
debug() |
DEBUG |
dim white |
success() |
SUCCESS |
bright_green |
warning() |
WARN |
bright_yellow |
error() |
ERROR |
bright_red |
critical() |
ERROR |
bright_red |
tip() |
TIP |
bright_magenta |
system() |
SYSTEM |
bright_blue |
install() |
INSTALL |
bright_green |
detect() |
DETECT |
bright_blue |
config() |
CONFIG |
bright_green |
deps() |
DEPS |
bright_cyan |
Note
critical() reuses the ERROR pattern and color. The distinction between error and critical is filtered by the log level numeric value, not by the visual pattern.