File size: 1,748 Bytes
46a8a46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""logging utility for all LangGraph agents"""

from rich.console import Console
from rich.text import Text

console = Console()

def log(agent_name: str, level: str, message: str, max_width: int = 15):
    """
    centralized logging function for all agents
    
    args:
        agent_name: name of the agent (e.g., "parser", "color_agent")
        level: log level (e.g., "info", "warning", "error", "success")
        message: the message to log
        max_width: maximum width for the agent name padding
    """
    # clean agent name for display
    display_name = agent_name.replace("_agent", "").replace("_node", "").replace("_", " ").title()
    
    # color scheme based on level
    level_colors = {
        "info": "cyan",
        "warning": "yellow", 
        "error": "red",
        "success": "green",
        "debug": "blue"
    }
    
    level_color = level_colors.get(level.lower(), "white")
    
    # create header with fixed width
    header = Text(f"[ {display_name:^{max_width}} ]", style=f"bold {level_color}")
    body = Text(message)
    
    console.print(header, body)


def log_agent_start(agent_name: str):
    """log agent start with separator"""
    log(agent_name, "info", f"starting {agent_name}...")


def log_agent_success(agent_name: str, message: str):
    """log agent success"""
    log(agent_name, "success", f"✅ {message}")


def log_agent_error(agent_name: str, message: str):
    """log agent error"""
    log(agent_name, "error", f"❌ {message}")


def log_agent_warning(agent_name: str, message: str):
    """log agent warning"""
    log(agent_name, "warning", f"⚠️ {message}")


def log_agent_info(agent_name: str, message: str):
    """log agent info"""
    log(agent_name, "info", message)