diff --git a/api/config/parsers.js b/api/config/parsers.js index 7cedd014cb..a3bab7d3cb 100644 --- a/api/config/parsers.js +++ b/api/config/parsers.js @@ -187,17 +187,33 @@ const debugTraverse = winston.format.printf(({ level, message, timestamp, ...met }); const jsonTruncateFormat = winston.format((info) => { + const truncateLongStrings = (str, maxLength) => { + return str.length > maxLength ? str.substring(0, maxLength) + '...' : str; + }; + + const seen = new WeakSet(); + const truncateObject = (obj) => { + if (typeof obj !== 'object' || obj === null) { + return obj; + } + + // Handle circular references + if (seen.has(obj)) { + return '[Circular]'; + } + seen.add(obj); + + if (Array.isArray(obj)) { + return obj.map(item => truncateObject(item)); + } + const newObj = {}; Object.entries(obj).forEach(([key, value]) => { if (typeof value === 'string') { newObj[key] = truncateLongStrings(value, 255); - } else if (Array.isArray(value)) { - newObj[key] = value.map(condenseArray); - } else if (typeof value === 'object' && value !== null) { - newObj[key] = truncateObject(value); } else { - newObj[key] = value; + newObj[key] = truncateObject(value); } }); return newObj;