Some checks are pending
CI/CD Pipeline / test (push) Waiting to run
- Simplified the FastAPI application structure and improved error handling with middleware. - Introduced a retry decorator for asynchronous functions to enhance reliability. - Modularized the LLM initialization and prompt loading into separate functions for better maintainability. - Updated Pydantic models for Jira webhook payload and analysis flags to ensure proper validation and structure. - Implemented a structured logging configuration for better traceability and debugging. - Added comprehensive unit tests for prompt loading, response validation, and webhook handling. - Established a CI/CD pipeline with GitHub Actions for automated testing and coverage reporting. - Enhanced the prompt template for LLM analysis to include specific instructions for handling escalations.
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
import sys
|
|
from loguru import logger
|
|
|
|
logger.configure(
|
|
extra={"request_id": "N/A"}
|
|
)
|
|
import os
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
def configure_logging(log_level: str = "INFO", log_dir: Optional[str] = None):
|
|
"""Configure structured logging for the application"""
|
|
|
|
# Default log directory
|
|
if not log_dir:
|
|
log_dir = os.getenv("LOG_DIR", "logs")
|
|
|
|
# Create log directory if it doesn't exist
|
|
Path(log_dir).mkdir(parents=True, exist_ok=True)
|
|
|
|
# Log file path with timestamp
|
|
log_file = Path(log_dir) / f"jira-webhook-llm_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
|
|
|
|
# Remove default logger
|
|
logger.remove()
|
|
|
|
# Add console logger
|
|
logger.add(
|
|
sys.stdout,
|
|
level=log_level,
|
|
format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level} | {extra[request_id]} | {message}",
|
|
colorize=True
|
|
)
|
|
|
|
# Add file logger
|
|
logger.add(
|
|
str(log_file),
|
|
level=log_level,
|
|
format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level} | {extra[request_id]} | {message}",
|
|
rotation="100 MB",
|
|
retention="30 days",
|
|
compression="zip"
|
|
)
|
|
|
|
logger.info("Logging configured successfully") |