MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / formatEntry

Function formatEntry

packages/agent-core/src/logging/formatter.ts:161–194  ·  view source on GitHub ↗
(entry: LogEntry, options: FormatOptions = {})

Source from the content-addressed store, hash-verified

159}
160
161export function formatEntry(entry: LogEntry, options: FormatOptions = {}): FormattedEntry {
162 const ctx = entry.ctx ? redactCtx(entry.ctx) : undefined;
163 const omitContextKeys = new Set(options.omitContextKeys ?? []);
164 const msg = truncate(entry.msg, MSG_MAX_CHARS);
165 const pairs: string[] = [];
166 if (ctx) {
167 for (const [k, v] of Object.entries(ctx)) {
168 if (omitContextKeys.has(k)) continue;
169 if (v !== undefined) pairs.push(formatPair(k, v));
170 }
171 }
172
173 const time = new Date(entry.t).toISOString();
174 const label = LEVEL_LABEL[entry.level];
175 const rendered = pairs.length === 0
176 ? `${time} ${label} ${msg}`
177 : `${time} ${label} ${msg} ${pairs.join(' ')}`;
178
179 let head = Buffer.byteLength(rendered, 'utf-8') > ENTRY_MAX_BYTES
180 ? clipBytes(rendered, ENTRY_MAX_BYTES)
181 : rendered;
182
183 if (options.ansi === true) {
184 head = `${ANSI_LEVEL[entry.level]}${head}${ANSI_RESET}`;
185 }
186
187 if (entry.error?.stack) {
188 head = `${head}\n${indentStack(clipStack(redactString(entry.error.stack)))}`;
189 } else if (entry.error?.message) {
190 head = `${head}\n Error: ${redactString(entry.error.message)}`;
191 }
192
193 return { text: head, dropped: false };
194}
195
196export function extractError(value: Error): { message: string; stack?: string } {
197 return typeof value.stack === 'string'

Callers 2

formatter.test.tsFile · 0.90
emitMethod · 0.90

Calls 9

redactCtxFunction · 0.85
formatPairFunction · 0.85
clipBytesFunction · 0.85
indentStackFunction · 0.85
clipStackFunction · 0.85
redactStringFunction · 0.85
truncateFunction · 0.70
hasMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected