Types and enums¶
Enums and protocols exported by ezplog.
ð API¶
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.) |
Pattern
¶
Bases: Enum
Contextual patterns for console output.
Patterns provide semantic meaning beyond log levels, allowing for more expressive and contextual logging.
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 |
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 |
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(), 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.
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(), 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.