mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-10-21 17:44:11 +00:00
🧹 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:
parent
b34628de85
commit
6bf9548ff2
2 changed files with 24 additions and 0 deletions
|
|
@ -43,6 +43,20 @@ describe('formatConsoleMeta', () => {
|
||||||
expect(meta).toBe('{"userField":"keep"}');
|
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', () => {
|
it('drops empty, null, undefined, function, and symbol values', () => {
|
||||||
const meta = formatConsoleMeta({
|
const meta = formatConsoleMeta({
|
||||||
level: 'warn',
|
level: 'warn',
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,16 @@ function extractMetaObject(source) {
|
||||||
if (RESERVED_LOG_KEYS.has(key) || key.startsWith('_')) {
|
if (RESERVED_LOG_KEYS.has(key) || key.startsWith('_')) {
|
||||||
continue;
|
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];
|
const value = source[key];
|
||||||
if (value === undefined || value === null || value === '') {
|
if (value === undefined || value === null || value === '') {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue