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
¶
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
¶
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 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 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 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 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
¶
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 available log levels.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of all available log level names |
get_rich_style
¶
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 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
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.
manage_indent
¶
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.
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¶
| Alias | Resolves to | Use |
|---|---|---|
Printer |
EzPrinter |
Type annotation for printer variables |
Logger |
EzLogger |
Type annotation for logger variables |