import logging import sys from datetime import datetime from pathlib import Path # Global logger configuration LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" LOG_LEVEL = logging.INFO def setup_logging(log_level=LOG_LEVEL): """Setup logging configuration""" logging.basicConfig( level=log_level, format=LOG_FORMAT, handlers=[ logging.StreamHandler(sys.stdout), ] ) def get_logger(name): """Get a logger instance""" return logging.getLogger(name) def log_error(logger, error_msg, exception=None, context=None): """Log error with additional context""" full_msg = f"{error_msg}" if context: full_msg += f" | Context: {context}" if exception: full_msg += f" | Exception: {str(exception)}" logger.error(full_msg) def log_info(logger, msg, context=None): """Log info with additional context""" full_msg = f"{msg}" if context: full_msg += f" | Context: {context}" logger.info(full_msg) def log_warning(logger, msg, context=None): """Log warning with additional context""" full_msg = f"{msg}" if context: full_msg += f" | Context: {context}" logger.warning(full_msg) def log_debug(logger, msg, context=None): """Log debug with additional context""" full_msg = f"{msg}" if context: full_msg += f" | Context: {context}" logger.debug(full_msg)