File size: 4,787 Bytes
a5784e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
"""
Logging Constants
"""

import sys
from typing import Dict

from colorama import Fore, Style
from colorama import init as colorama_init

# =============================================================================
# Initialize colorama for Windows compatibility
# =============================================================================
colorama_init(autoreset=False)

# Enable Windows 10+ ANSI support
if sys.platform == "win32":
    try:
        import ctypes

        kernel32 = ctypes.windll.kernel32  # type: ignore[attr-defined]
        kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
    except Exception:
        pass  # Graceful fallback


# =============================================================================
# Source Mapping (Normalize to 5-letter codes)
# =============================================================================

SOURCE_MAP: Dict[str, str] = {
    # API/Server sources
    "api": "API  ",
    "server": "SERVR",
    "system": "SYS  ",
    "sys": "SYS  ",
    # Worker/Queue sources
    "worker": "WORKR",
    "workr": "WORKR",
    "processo": "WORKR",
    "processor": "WORKR",
    "queue": "QUEUE",
    "queue_worker": "WORKR",
    # Proxy/Stream sources
    "proxy": "PROXY",
    "proxy_server": "PROXY",
    "proxyserver": "PROXY",
    "stream": "STRM ",
    "inter": "INTER",
    "http_interceptor": "INTER",
    "interceptor": "INTER",
    # Browser sources
    "browser": "BROWR",
    "browr": "BROWR",
    "page": "PAGE ",
    "ui": "UI   ",
    # Launcher sources
    "launcher": "LNCHR",
    "lnchr": "LNCHR",
    "camoufoxlauncher": "LNCHR",
    # Auth sources
    "auth": "AUTH ",
    # Config sources
    "config": "CONFG",
    # Network sources
    "net": "NET  ",
    "network": "NET  ",
    # Model management
    "model": "MODEL",
    # Debug
    "debug": "DEBUG",
}


# =============================================================================
# Column Configuration
# =============================================================================


class Columns:
    """Fixed column widths for grid alignment."""

    TIME = 12  # HH:MM:SS.mmm
    LEVEL = 3  # INF, WRN, ERR, DBG, CRT
    SOURCE = 5  # Fixed 5-letter source code
    ID = 7  # Request ID (truncated/padded)
    TREE_INDENT = 3  # Each tree level width


# =============================================================================
# Color Definitions
# =============================================================================


class Colors:
    """Centralized color definitions for consistent theming."""

    # Reset
    RESET = Style.RESET_ALL

    # Time column - dim/subtle (dark grey)
    TIME = Style.DIM + Fore.WHITE

    # Level colors (high contrast)
    LEVELS: Dict[str, str] = {
        "DEBUG": Style.DIM + Fore.CYAN,
        "INFO": Fore.WHITE,
        "WARNING": Fore.YELLOW + Style.BRIGHT,
        "ERROR": Fore.RED + Style.BRIGHT,
        "CRITICAL": Fore.RED + Style.BRIGHT,
    }

    # Level abbreviations
    LEVEL_ABBREV: Dict[str, str] = {
        "DEBUG": "DBG",
        "INFO": "INF",
        "WARNING": "WRN",
        "ERROR": "ERR",
        "CRITICAL": "CRT",
    }

    # Source colors (distinct, pastel-ish)
    SOURCES: Dict[str, str] = {
        "API  ": Fore.LIGHTBLUE_EX,
        "SERVR": Fore.MAGENTA,
        "SYS  ": Style.DIM + Fore.WHITE,
        "WORKR": Fore.LIGHTYELLOW_EX,
        "QUEUE": Fore.YELLOW,
        "PROXY": Fore.BLUE,
        "STRM ": Fore.GREEN,
        "INTER": Fore.LIGHTCYAN_EX,
        "BROWR": Fore.CYAN,
        "PAGE ": Fore.CYAN,
        "UI   ": Fore.LIGHTMAGENTA_EX,
        "LNCHR": Fore.LIGHTGREEN_EX,
        "AUTH ": Fore.LIGHTRED_EX,
        "CONFG": Style.DIM + Fore.WHITE,
        "NET  ": Fore.LIGHTCYAN_EX,
        "MODEL": Fore.LIGHTMAGENTA_EX,
        "DEBUG": Style.DIM + Fore.CYAN,
    }

    # Request ID - dim
    REQUEST_ID = Style.DIM + Fore.WHITE

    # Tree structure - dim
    TREE = Style.DIM + Fore.WHITE

    # Message - default white
    MESSAGE = Fore.WHITE

    # Semantic highlighting (updated for new scheme)
    STRING = Fore.CYAN  # Strings/IDs: Cyan
    NUMBER = Fore.MAGENTA  # Numbers: Magenta
    BOOLEAN_TRUE = Fore.GREEN  # True: Green
    BOOLEAN_FALSE = Fore.RED  # False: Red
    BOOLEAN_NONE = Style.DIM + Fore.WHITE  # None: Dim
    URL = Style.DIM + Fore.BLUE  # URLs: Faint Blue
    KEY = Fore.LIGHTBLUE_EX  # Keys in key:value
    TAG = Style.BRIGHT + Fore.WHITE  # Tags like [UI]

    # Key phrases (Bold)
    PHRASE_ERROR = Style.BRIGHT + Fore.RED
    PHRASE_FAILED = Style.BRIGHT + Fore.RED
    PHRASE_SUCCESS = Style.BRIGHT + Fore.GREEN
    PHRASE_WARNING = Style.BRIGHT + Fore.YELLOW

    # Burst count indicator
    BURST_COUNT = Fore.YELLOW

    # Separator (unused now)
    SEPARATOR = Style.DIM + Fore.WHITE