From e3918bf86fd5b829a7bd39d91c6a488d8d27a2b4 Mon Sep 17 00:00:00 2001 From: Yuchen Liu Date: Sat, 21 Dec 2024 12:02:11 +0800 Subject: [PATCH] bug fix of object cannot be printed in log --- util/logger.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/util/logger.js b/util/logger.js index 47d27d1d..0189d57a 100644 --- a/util/logger.js +++ b/util/logger.js @@ -42,21 +42,24 @@ if (process.env.FWDEBUG) { } const keysToRedact = new Set(["password", "passwd", "psk", "key", "psks"]); -// pass in function arguments object and returns string with whitespaces function redactLog(obj, redactRequired = false) { if (!obj) return obj; // obj should be either object or array + const objCopy = _.isArray(obj) ? [] : Object.create(obj); try { for (const key of Object.keys(obj)) { if (_.isObject(obj[key]) || _.isArray(obj[key])) - redactLog(obj[key], redactRequired || keysToRedact.has(key)); + objCopy[key] = redactLog(obj[key], redactRequired || keysToRedact.has(key)); else { if (redactRequired || keysToRedact.has(key)) - obj[key] = "*** redacted ***"; + objCopy[key] = "*** redacted ***"; + else + objCopy[key] = obj[key]; } } } catch (err) {} + return objCopy; } // pass in function arguments object and returns string with whitespaces @@ -66,8 +69,8 @@ function argumentsToString(v) { for (var k in args) { if (typeof args[k] === "object") { // args[k] = JSON.stringify(args[k]); - args[k] = JSON.parse(JSON.stringify(args[k])); - redactLog(args[k]); + if (_.isArray(args[k]) || _.isObject(args[k])) + args[k] = redactLog(args[k]); args[k] = require('util').inspect(args[k], false, null, true); } }