MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / logLine

Method logLine

src/python/stderr.ts:49–92  ·  view source on GitHub ↗
(line: string)

Source from the content-addressed store, hash-verified

47 }
48
49 private logLine(line: string): void {
50 if (!line.trim()) {
51 this.inTraceback = false;
52 return;
53 }
54
55 if (this.inTraceback && /^\s/.test(line)) {
56 this.writeLog('error', line);
57 return;
58 }
59
60 const trimmedStart = line.trimStart();
61 if (/^Traceback \(most recent call last\):/i.test(trimmedStart)) {
62 this.inTraceback = true;
63 this.writeLog('error', line);
64 return;
65 }
66
67 const prefixMatch = /^(DEBUG|INFO|WARN|WARNING|ERROR|CRITICAL|FATAL)\b[: ]?/i.exec(
68 trimmedStart,
69 );
70 if (prefixMatch) {
71 this.inTraceback = false;
72 this.writeLog(this.normalizeLevel(prefixMatch[1]), line);
73 return;
74 }
75
76 if (this.inTraceback) {
77 this.inTraceback = false;
78 this.writeLog('error', line);
79 return;
80 }
81
82 if (
83 /^(During handling of the above exception|The above exception was the direct cause)/i.test(
84 trimmedStart,
85 )
86 ) {
87 this.writeLog('error', line);
88 return;
89 }
90
91 this.writeLog('warn', line);
92 }
93
94 private normalizeLevel(level: string): StderrLevel {
95 switch (level.toUpperCase()) {

Callers 2

handleDataMethod · 0.95
flushMethod · 0.95

Calls 2

writeLogMethod · 0.95
normalizeLevelMethod · 0.95

Tested by

no test coverage detected