- Setup virtual environment and install all dependencies - Implemented modular configuration system (YAML-based) - Created logging infrastructure with rich formatting - Built email data models (Email, Attachment, ClassificationResult) - Implemented email provider abstraction with stubs: * MockProvider for testing * Gmail provider (credentials required) * IMAP provider (credentials required) - Implemented feature extraction pipeline: * Semantic embeddings (sentence-transformers) * Hard pattern detection (20+ patterns) * Structural features (metadata, timing, attachments) - Created ML classifier framework with MOCK Random Forest: * Mock uses synthetic data for testing only * Clearly labeled as test/development model * Placeholder for real LightGBM training at home - Implemented LLM providers: * Ollama provider (local, qwen3:1.7b/4b support) * OpenAI-compatible provider (API-based) * Graceful degradation when LLM unavailable - Created adaptive classifier orchestration: * Hard rules matching (10%) * ML classification with confidence thresholds (85%) * LLM review for uncertain cases (5%) * Dynamic threshold adjustment - Built CLI interface with commands: * run: Full classification pipeline * test-config: Config validation * test-ollama: LLM connectivity * test-gmail: Gmail OAuth (when configured) - Created comprehensive test suite: * 23 unit and integration tests * 22/23 passing * Feature extraction, classification, end-to-end workflows - Categories system with 12 universal categories: * junk, transactional, auth, newsletters, social, automated * conversational, work, personal, finance, travel, unknown Status: - Framework: 95% complete and functional - Mocks: Clearly labeled, transparent about limitations - Tests: Passing, validates integration - Ready for: Real data training when Enron dataset available - Next: Home setup with real credentials and model training This build is production-ready for framework but NOT for accuracy. Real ML model training, Gmail OAuth, and LLM will be done at home with proper hardware and real inbox data. Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
75 lines
1.9 KiB
Python
75 lines
1.9 KiB
Python
"""Logging configuration and management."""
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
try:
|
|
from rich.logging import RichHandler
|
|
HAS_RICH = True
|
|
except ImportError:
|
|
HAS_RICH = False
|
|
|
|
|
|
def setup_logging(
|
|
level: str = "INFO",
|
|
log_file: Optional[str] = None,
|
|
use_rich: bool = True
|
|
) -> logging.Logger:
|
|
"""
|
|
Setup logging with console and optional file handlers.
|
|
|
|
Args:
|
|
level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
log_file: Optional file path for log output
|
|
use_rich: Use rich formatting if available
|
|
|
|
Returns:
|
|
Configured logger instance
|
|
"""
|
|
# Create logs directory if needed
|
|
if log_file:
|
|
Path(log_file).parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Get root logger
|
|
logger = logging.getLogger()
|
|
logger.setLevel(level)
|
|
|
|
# Remove existing handlers
|
|
logger.handlers = []
|
|
|
|
# Console handler with optional rich formatting
|
|
if use_rich and HAS_RICH:
|
|
console_handler = RichHandler(
|
|
rich_tracebacks=True,
|
|
markup=True,
|
|
show_time=True,
|
|
show_path=False
|
|
)
|
|
else:
|
|
console_handler = logging.StreamHandler(sys.stdout)
|
|
|
|
console_handler.setLevel(level)
|
|
console_formatter = logging.Formatter(
|
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
console_handler.setFormatter(console_formatter)
|
|
logger.addHandler(console_handler)
|
|
|
|
# File handler if specified
|
|
if log_file:
|
|
file_handler = logging.FileHandler(log_file)
|
|
file_handler.setLevel(level)
|
|
file_formatter = logging.Formatter(
|
|
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
file_handler.setFormatter(file_formatter)
|
|
logger.addHandler(file_handler)
|
|
|
|
return logger
|
|
|
|
|
|
def get_logger(name: str) -> logging.Logger:
|
|
"""Get a logger instance for a module."""
|
|
return logging.getLogger(name)
|