haive.core.common.mixins.rich_logger_mixin¶
Rich logging mixin for enhanced console output.
This module provides a mixin for adding rich console logging capabilities to Pydantic models. It leverages the Rich library to enable colorized, formatted console output with features like syntax highlighting and rich traceback display.
- Usage:
from pydantic import BaseModel from haive.core.common.mixins import RichLoggerMixin
- class MyProcessor(RichLoggerMixin, BaseModel):
name: str
- def process(self, data):
self._info(f”Processing data with {self.name}”) try:
# Processing logic result = self._process_data(data) self._debug(f”Processed result: {result}”) return result
- except Exception as e:
self._error(f”Failed to process data: {e}”) raise
# Create with debug enabled processor = MyProcessor(name=”TestProcessor”, debug=True) processor.process({“test”: “data”})
Classes¶
Mixin that provides rich console logging capabilities. |
Module Contents¶
- class haive.core.common.mixins.rich_logger_mixin.RichLoggerMixin(/, **data)[source]¶
Bases:
pydantic.BaseModelMixin that provides rich console logging capabilities.
This mixin adds a configurable logger with rich formatting to any Pydantic model. It creates a logger named after the class, configures it with Rich’s handler for pretty console output, and provides convenience methods for different log levels with appropriate styling.
- Parameters:
data (Any)
- debug¶
Boolean flag to control debug output visibility.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- property logger: logging.Logger¶
Get or create logger with rich handler.
This property lazily initializes a logger with a Rich handler, creating it only when first accessed. The logger is named using the module and class name for proper log categorization.
- Returns:
Configured logging.Logger instance with Rich formatting.
- Return type: