File size: 3,517 Bytes
e7abd9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import logging
import sys
from typing import Dict, Any, List, Optional

logger = logging.getLogger(__name__)

class LogFormatter:
    """Utility class for consistent log formatting across the application"""
    
    @staticmethod
    def section(title: str) -> str:
        """Create a section header"""
        return f"\n{'='*20} {title.upper()} {'='*20}"
    
    @staticmethod
    def subsection(title: str) -> str:
        """Create a subsection header"""
        return f"\n{'─'*20} {title} {'─'*20}"
    
    @staticmethod
    def tree(items: Dict[str, Any], title: str = None) -> List[str]:
        """Create a tree view of dictionary data"""
        lines = []
        if title:
            lines.append(f"πŸ“Š {title}:")
        
        # Get the maximum length for alignment
        max_key_length = max(len(str(k)) for k in items.keys())
        
        # Format each item
        for i, (key, value) in enumerate(items.items()):
            prefix = "└──" if i == len(items) - 1 else "β”œβ”€β”€"
            if isinstance(value, (int, float)):
                value = f"{value:,}"  # Add thousand separators
            lines.append(f"{prefix} {str(key):<{max_key_length}}: {value}")
        
        return lines
    
    @staticmethod
    def stats(stats: Dict[str, int], title: str = None) -> List[str]:
        """Format statistics with icons"""
        lines = []
        if title:
            lines.append(f"πŸ“Š {title}:")
        
        # Get the maximum length for alignment
        max_key_length = max(len(str(k)) for k in stats.keys())
        
        # Format each stat with an appropriate icon
        icons = {
            "total": "πŸ“Œ",
            "success": "βœ…",
            "error": "❌",
            "pending": "⏳",
            "processing": "βš™οΈ",
            "finished": "✨",
            "evaluating": "πŸ”„",
            "downloads": "⬇️",
            "files": "πŸ“",
            "cached": "πŸ’Ύ",
            "size": "πŸ“",
            "time": "⏱️",
            "rate": "πŸš€"
        }
        
        # Format each item
        for i, (key, value) in enumerate(stats.items()):
            prefix = "└──" if i == len(stats) - 1 else "β”œβ”€β”€"
            icon = icons.get(key.lower().split('_')[0], "β€’")
            if isinstance(value, (int, float)):
                value = f"{value:,}"  # Add thousand separators
            lines.append(f"{prefix} {icon} {str(key):<{max_key_length}}: {value}")
        
        return lines
    
    @staticmethod
    def progress_bar(current: int, total: int, width: int = 20) -> str:
        """Create a progress bar"""
        percentage = (current * 100) // total
        filled = "β–ˆ" * (percentage * width // 100)
        empty = "β–‘" * (width - len(filled))
        return f"{filled}{empty} {percentage:3d}%"
    
    @staticmethod
    def error(message: str, error: Optional[Exception] = None) -> str:
        """Format error message"""
        error_msg = f"\n❌ Error: {message}"
        if error:
            error_msg += f"\n   └── Details: {str(error)}"
        return error_msg
    
    @staticmethod
    def success(message: str) -> str:
        """Format success message"""
        return f"βœ… {message}"
    
    @staticmethod
    def warning(message: str) -> str:
        """Format warning message"""
        return f"⚠️  {message}"
    
    @staticmethod
    def info(message: str) -> str:
        """Format info message"""
        return f"ℹ️  {message}"