MCPcopy
hub / github.com/OpenBMB/ChatDev / add_log

Method add_log

utils/logger.py:81–136  ·  view source on GitHub ↗

Add a log entry.

(self, level: LogLevel, message: str = None, node_id: str = None,
                event_type: EventType = None, details: Dict[str, Any] = None,
                duration: float = None)

Source from the content-addressed store, hash-verified

79 self.structured_logger = get_workflow_logger(self.workflow_id)
80
81 def add_log(self, level: LogLevel, message: str = None, node_id: str = None,
82 event_type: EventType = None, details: Dict[str, Any] = None,
83 duration: float = None) -> LogEntry | None:
84 """Add a log entry."""
85 if level < self.log_level:
86 return None
87
88 timestamp = datetime.now().isoformat()
89 execution_path = copy.deepcopy(self.current_path)
90
91 safe_details = _json_safe(details or {})
92
93 log_entry = LogEntry(
94 timestamp=timestamp,
95 level=level,
96 node_id=node_id,
97 event_type=event_type,
98 message=message,
99 details=safe_details,
100 execution_path=execution_path,
101 duration=duration
102 )
103 self.logs.append(log_entry)
104
105 # Log to console if enabled
106 if self.log_to_console:
107 print(f"[{timestamp}] [{level.value}] "
108 f"{f'Node {node_id} - ' if node_id else ''}"
109 f"{f'Event {event_type} - ' if event_type else ''}"
110 f"{message} "
111 f"{f'Details: {details} ' if details else ''}"
112 f"{f'Duration: {duration}' if duration else ''}")
113
114 # Log using structured logger if enabled
115 if self.use_structured_logging and self.structured_logger:
116 structured_details = {
117 "workflow_id": self.workflow_id,
118 "node_id": node_id,
119 "event_type": event_type.value if event_type else None,
120 "execution_path": execution_path,
121 "duration": duration,
122 **safe_details
123 }
124
125 if level == LogLevel.DEBUG:
126 self.structured_logger.debug(message, **structured_details)
127 elif level == LogLevel.INFO:
128 self.structured_logger.info(message, **structured_details)
129 elif level == LogLevel.WARNING:
130 self.structured_logger.warning(message, **structured_details)
131 elif level == LogLevel.ERROR:
132 self.structured_logger.error(message, **structured_details)
133 elif level == LogLevel.CRITICAL:
134 self.structured_logger.critical(message, **structured_details)
135
136 return log_entry
137
138 def debug(self, message: str, node_id: str = None, event_type: EventType = None,

Callers 7

debugMethod · 0.95
infoMethod · 0.95
warningMethod · 0.95
errorMethod · 0.95
criticalMethod · 0.95
record_tool_callMethod · 0.95
record_workflow_endMethod · 0.95

Calls 7

_json_safeFunction · 0.85
LogEntryClass · 0.85
debugMethod · 0.45
infoMethod · 0.45
warningMethod · 0.45
errorMethod · 0.45
criticalMethod · 0.45

Tested by

no test coverage detected