Spaces:
Sleeping
Sleeping
| """ | |
| Logging setup for GEPA Optimizer. | |
| This module provides backward-compatible logging functions that delegate | |
| to the centralized logging infrastructure. | |
| For new code, prefer importing directly from infrastructure.logging: | |
| from gepa_optimizer.infrastructure.logging import get_logger, configure_logging | |
| """ | |
| import logging | |
| from pathlib import Path | |
| from datetime import datetime | |
| from typing import Optional, Union | |
| # Import from centralized infrastructure | |
| from ..infrastructure.logging import ( | |
| get_logger as _get_logger, | |
| configure_logging as _configure_logging, | |
| LogLevel, | |
| ) | |
| def setup_logging( | |
| level: str = "INFO", | |
| log_file: Optional[Union[str, bool]] = None, | |
| use_colors: bool = True, | |
| include_emoji: bool = True, | |
| ) -> None: | |
| """ | |
| Configure logging for GEPA Optimizer with optional file logging. | |
| This function provides backward compatibility with existing code. | |
| New code should use configure_logging() from infrastructure.logging. | |
| Args: | |
| level: Logging level (e.g. "DEBUG", "INFO", "WARNING") | |
| log_file: Path to log file. | |
| - None: Auto-generates timestamped filename in logs/ | |
| - False: Disables file logging | |
| - str: Uses specified path | |
| use_colors: Whether to use colored output in console | |
| include_emoji: Whether to include emoji in log messages | |
| Example: | |
| # Basic setup | |
| setup_logging(level="INFO") | |
| # With file logging | |
| setup_logging(level="DEBUG", log_file="optimization.log") | |
| # Console only, no colors | |
| setup_logging(level="INFO", log_file=False, use_colors=False) | |
| """ | |
| # Handle auto-generated log file | |
| actual_log_file: Optional[str] = None | |
| if log_file is None: | |
| # Auto-generate log filename with timestamp | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| log_dir = Path("logs") | |
| log_dir.mkdir(exist_ok=True) | |
| actual_log_file = str(log_dir / f"optimization_{timestamp}.log") | |
| elif log_file is not False: | |
| # Use specified path | |
| log_path = Path(log_file) | |
| log_path.parent.mkdir(parents=True, exist_ok=True) | |
| actual_log_file = str(log_file) | |
| # Delegate to centralized configuration | |
| _configure_logging( | |
| level=level, | |
| log_file=actual_log_file, | |
| use_colors=use_colors, | |
| include_emoji=include_emoji, | |
| ) | |
| # Log configuration info | |
| logger = _get_logger(__name__) | |
| if actual_log_file: | |
| logger.info(f"Logging to file: {actual_log_file}") | |
| logger.info(f"Logging configured at {level} level (console + file)") | |
| else: | |
| logger.info(f"Logging configured at {level} level (console only)") | |
| def get_logger(name: str) -> logging.Logger: | |
| """ | |
| Get a logger for a specific module. | |
| This function provides backward compatibility. New code should use: | |
| from gepa_optimizer.infrastructure.logging import get_logger | |
| Args: | |
| name: Module name (typically __name__) | |
| Returns: | |
| Configured Logger instance | |
| """ | |
| return _get_logger(name) | |
| # Re-export for convenience | |
| __all__ = [ | |
| "setup_logging", | |
| "get_logger", | |
| ] | |