Skip to content

Types and enums

Enums and protocols exported by ezplog.

🔍 API

LogLevel

LogLevel(label: str, no: int, fg: str, bg: str)

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

get_attribute(level: str, attribute: str) -> Any

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_label(level: str) -> str

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_no(level: str) -> int

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_fgcolor(level: str) -> str

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_bgcolor(level: str) -> str

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

is_valid_level(level: str) -> bool

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_levels() -> list[str]

Get all available log levels.

Returns:

Type Description
list[str]

List of all available log level names

get_rich_style

get_rich_style() -> str

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_pattern_color_by_name(pattern_name: str) -> str

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

level property

level: str

Get the current logging level.

wizard property

wizard: Any

Get RichWizard instance for advanced features.

info

info(message: Any) -> None

Log an info message.

debug

debug(message: Any) -> None

Log a debug message.

success

success(message: Any) -> None

Log a success message.

warning

warning(message: Any) -> None

Log a warning message.

error

error(message: Any) -> None

Log an error message.

critical

critical(message: Any) -> None

Log a critical message.

tip

tip(message: Any) -> None

Display a tip message.

system

system(message: Any) -> None

Display a system message.

install

install(message: Any) -> None

Display an installation message.

detect

detect(message: Any) -> None

Display a detection message.

config

config(message: Any) -> None

Display a configuration message.

deps

deps(message: Any) -> None

Display a dependencies message.

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.

set_level

set_level(level: str) -> None

Set the logging level.

log

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

Log a message with specified level.

add_indent

add_indent() -> None

Increase indentation level.

del_indent

del_indent() -> None

Decrease indentation level.

reset_indent

reset_indent() -> None

Reset indentation to zero.

manage_indent

manage_indent() -> AbstractContextManager[None]

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.

level property

level: str

Get the current logging level.

trace

trace(message: Any, *args, **kwargs) -> None

Log a trace message.

debug

debug(message: Any, *args, **kwargs) -> None

Log a debug message.

info

info(message: Any, *args, **kwargs) -> None

Log an info message.

success

success(message: Any, *args, **kwargs) -> None

Log a success message.

warning

warning(message: Any, *args, **kwargs) -> None

Log a warning message.

error

error(message: Any, *args, **kwargs) -> None

Log an error message.

critical

critical(message: Any, *args, **kwargs) -> None

Log a critical message.

exception

exception(message: Any, *args, **kwargs) -> None

Log an exception with traceback.

bind

bind(**kwargs: Any) -> Any

Bind context variables to the logger.

opt

opt(**kwargs: Any) -> Any

Configure logger options.

patch

patch(patcher: Any) -> Any

Patch log records.

set_level

set_level(level: str) -> None

Set the logging level.

log

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

Log a message with specified level.

add_separator

add_separator() -> None

Add a session separator to the log file.

get_log_file

get_log_file() -> Path

Get the current log file path.

close

close() -> None

Close the logger and release resources.