tessl install tessl/pypi-kedro@1.1.0Kedro helps you build production-ready data and analytics pipelines
Agent Success
Agent success rate when using this tile
98%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.32x
Baseline
Agent success rate without this tile
74%
Rich logging handler and configuration utilities for enhanced console output.
class RichHandler:
"""
Logging handler using Rich library for enhanced console output.
Provides colored, formatted logs with rich formatting support.
Integrates with Python's standard logging module.
"""
def __init__(
self,
level: int | str = 0,
console: Console | None = None,
show_time: bool = True,
show_path: bool = True,
enable_link_path: bool = True,
markup: bool = False,
rich_tracebacks: bool = False,
tracebacks_width: int | None = None,
tracebacks_extra_lines: int = 3,
tracebacks_theme: str | None = None,
tracebacks_word_wrap: bool = True,
tracebacks_show_locals: bool = False,
tracebacks_suppress: list[str] | None = None,
locals_max_length: int = 10,
locals_max_string: int = 80
):
"""
Initialize RichHandler.
Parameters:
- level: Minimum log level to handle
- console: Rich Console instance (creates default if None)
- show_time: Show timestamp in log output
- show_path: Show file path in log output
- enable_link_path: Enable clickable file paths
- markup: Enable Rich markup in messages
- rich_tracebacks: Use Rich for exception formatting
- tracebacks_width: Width of traceback output
- tracebacks_extra_lines: Extra lines of context in tracebacks
- tracebacks_theme: Syntax highlighting theme for tracebacks
- tracebacks_word_wrap: Enable word wrap in tracebacks
- tracebacks_show_locals: Show local variables in tracebacks
- tracebacks_suppress: Modules to suppress from tracebacks
- locals_max_length: Max items to show in locals
- locals_max_string: Max string length in locals
"""def configure_logging(logging_config: dict[str, Any]) -> None:
"""
Configure Python logging from configuration dictionary.
Parameters:
- logging_config: Logging configuration dictionary compatible with
logging.config.dictConfig format
Example:
>>> config = {
... 'version': 1,
... 'handlers': {
... 'console': {
... 'class': 'kedro.logging.RichHandler',
... 'level': 'INFO'
... }
... },
... 'root': {
... 'handlers': ['console'],
... 'level': 'INFO'
... }
... }
>>> configure_logging(config)
"""import logging
from kedro.logging import RichHandler
# Configure logging with RichHandler
handler = RichHandler(
level=logging.INFO,
show_time=True,
show_path=True,
rich_tracebacks=True
)
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
# Use logger
logger.info("Pipeline started")
logger.warning("Resource usage high")
logger.error("Operation failed")from kedro.logging import configure_logging
logging_config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
}
},
'handlers': {
'console': {
'class': 'kedro.logging.RichHandler',
'level': 'INFO',
'show_time': True,
'rich_tracebacks': True,
'tracebacks_show_locals': True
},
'file': {
'class': 'logging.FileHandler',
'filename': 'kedro.log',
'level': 'DEBUG',
'formatter': 'simple'
}
},
'loggers': {
'kedro': {
'level': 'INFO',
'handlers': ['console', 'file']
}
},
'root': {
'level': 'INFO',
'handlers': ['console']
}
}
configure_logging(logging_config)from kedro.logging import RichHandler
import logging
# Enable rich tracebacks
handler = RichHandler(
rich_tracebacks=True,
tracebacks_show_locals=True,
tracebacks_theme='monokai'
)
logger = logging.getLogger()
logger.addHandler(handler)
# Exceptions will be beautifully formatted
try:
result = 1 / 0
except Exception as e:
logger.exception("Division error")See also: