File size: 1,839 Bytes
8b7e8f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import logging
import os
from datetime import datetime
from src.utils.config import config


def setup_logging():
    """Set up logging configuration."""
    # Create data directory if it doesn't exist
    os.makedirs(os.path.dirname(config.LOG_FILE), exist_ok=True)

    # Configure logging
    logging.basicConfig(
        level=getattr(logging, config.LOG_LEVEL),
        format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
        handlers=[logging.FileHandler(config.LOG_FILE), logging.StreamHandler()],
    )

    return logging.getLogger(__name__)


def log_document_upload(filename: str, file_size: int) -> None:
    """Log document upload event."""
    logger = logging.getLogger(__name__)
    logger.info(f"Document uploaded: {filename} ({file_size} bytes)")


def log_analysis_start(document_id: str) -> None:
    """Log analysis start event."""
    logger = logging.getLogger(__name__)
    logger.info(f"Starting analysis for document: {document_id}")


def log_analysis_complete(document_id: str, processing_time: float) -> None:
    """Log analysis completion event."""
    logger = logging.getLogger(__name__)
    logger.info(
        f"Analysis completed for document: {document_id} in {processing_time:.2f}s"
    )


def log_error(error_message: str, document_id: str = None) -> None:
    """Log error event."""
    logger = logging.getLogger(__name__)
    if document_id:
        logger.error(f"Error processing document {document_id}: {error_message}")
    else:
        logger.error(f"Application error: {error_message}")


def log_qa_interaction(document_id: str, question: str) -> None:
    """Log Q&A interaction."""
    logger = logging.getLogger(__name__)
    logger.info(f"Q&A interaction for document {document_id}: {question[:100]}...")


# Initialize logging when module is imported
setup_logging()