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_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"})
Functions¶
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: