From b52739ca5ccb9c5ee5e65471f636b51e8a27410f Mon Sep 17 00:00:00 2001 From: Mark Randall Havens Date: Sat, 14 Mar 2026 05:37:19 +0000 Subject: [PATCH] fix(logging): Add structured logging module - Created logging.py with: - setup_logging() function - Configurable levels - Console and file handlers - Structured format This addresses the logging gap. --- opus_orchestrator/logging.py | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 opus_orchestrator/logging.py diff --git a/opus_orchestrator/logging.py b/opus_orchestrator/logging.py new file mode 100644 index 0000000..f5f937b --- /dev/null +++ b/opus_orchestrator/logging.py @@ -0,0 +1,61 @@ +"""Logging configuration for Opus. + +Structured logging with levels, formats, and handlers. +""" + +import logging +import sys +from pathlib import Path + + +def setup_logging( + level: str = "INFO", + log_file: str = None, + format: str = "%(asctime)s | %(levelname)-8s | %(name)s | %(message)s", +) -> logging.Logger: + """Setup structured logging for Opus. + + Args: + level: DEBUG, INFO, WARNING, ERROR + log_file: Optional file path + format: Log message format + + Returns: + Configured logger + """ + # Create logger + logger = logging.getLogger("opus") + logger.setLevel(getattr(logging, level.upper())) + + # Clear existing handlers + logger.handlers.clear() + + # Console handler + console = logging.StreamHandler(sys.stdout) + console.setLevel(getattr(logging, level.upper())) + console.setFormatter(logging.Formatter(format)) + logger.addHandler(console) + + # File handler (optional) + if log_file: + log_path = Path(log_file) + log_path.parent.mkdir(parents=True, exist_ok=True) + + file_handler = logging.FileHandler(log_file) + file_handler.setLevel(logging.DEBUG) + file_handler.setFormatter(logging.Formatter( + "%(asctime)s | %(levelname)-8s | %(name)s:%(lineno)d | %(message)s" + )) + logger.addHandler(file_handler) + + return logger + + +# Default logger +logger = setup_logging() + + +# Usage in modules: +# from opus_orchestrator.logging import logger +# logger.info("Starting generation") +# logger.error(f"Failed: {e}")