MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / parseAgentServerLogLine

Function parseAgentServerLogLine

scripts/dev-with-automation.mjs:165–186  ·  view source on GitHub ↗

* Parse one JSON log line produced by the SDK's JsonFormatter and return a * single-line human-readable string + an appropriate ANSI color. * * Returns null for non-JSON lines so callers can fall back to the raw text. * * @param {string} rawLine * @returns {{ text: string; color: string } | nu

(rawLine)

Source from the content-addressed store, hash-verified

163 * @returns {{ text: string; color: string } | null}
164 */
165function parseAgentServerLogLine(rawLine) {
166 try {
167 const obj = JSON.parse(rawLine);
168 if (!obj.levelname || obj.message === undefined) return null;
169 const level = obj.levelname.padEnd(8);
170 const location =
171 obj.filename && obj.lineno ? ` ${obj.filename}:${obj.lineno}` : "";
172 const text = `${level} ${obj.message}${location}`;
173 const lvl = obj.levelname;
174 const color =
175 lvl === "DEBUG"
176 ? c.dim
177 : lvl === "WARNING"
178 ? c.yellow
179 : lvl === "ERROR" || lvl === "CRITICAL"
180 ? c.red
181 : c.blue;
182 return { text, color };
183 } catch {
184 return null;
185 }
186}
187
188// ═══════════════════════════════════════════════════════════════════════════
189// Configuration

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected