🧹 fix: Skip Numeric Splat Keys When Extracting Log Metadata

When a caller passes a primitive as the second argument — e.g.
`logger.warn('Unhandled step creation type:', step.type)` — winston /
`format.splat()` can leave character-index keys (`"0"`, `"1"`, …) on the
`info` object. With the warn/error metadata trailer in play, those
synthetic artifacts were being surfaced as bogus metadata, producing
noisy console and debug-file output.

Filter out numeric-string keys in `extractMetaObject` so only real
metadata fields reach the trailer. Added a regression test.

Reviewed-by: Codex (P2 finding on PR #12737, commit b34628de).
This commit is contained in:
Danny Avila 2026-04-18 11:59:40 -04:00
parent b34628de85
commit 6bf9548ff2
2 changed files with 24 additions and 0 deletions

View file

@ -43,6 +43,20 @@ describe('formatConsoleMeta', () => {
expect(meta).toBe('{"userField":"keep"}');
});
it('drops numeric-index-like keys (splat artifacts from primitive args)', () => {
const meta = formatConsoleMeta({
level: 'warn',
message: 'Unhandled step:',
timestamp: 'ts',
0: 'f',
1: 'o',
2: 'o',
realField: 'real',
});
expect(meta).toBe('{"realField":"real"}');
});
it('drops empty, null, undefined, function, and symbol values', () => {
const meta = formatConsoleMeta({
level: 'warn',

View file

@ -110,6 +110,16 @@ function extractMetaObject(source) {
if (RESERVED_LOG_KEYS.has(key) || key.startsWith('_')) {
continue;
}
/*
* Skip numeric-index-like keys. When a caller passes a primitive as
* the second argument to `logger.warn/error`, `format.splat()` can
* leave character-index keys ("0", "1", ...) on `info`. Those are
* synthetic splat artifacts, not real metadata, and would otherwise
* produce noisy output now that warn/error share this path.
*/
if (/^\d+$/.test(key)) {
continue;
}
const value = source[key];
if (value === undefined || value === null || value === '') {
continue;