Skip to content

Commit

Permalink
Merge pull request #1431 from jasonlyc/bug_fix
Browse files Browse the repository at this point in the history
bug fix of object cannot be printed in log
  • Loading branch information
MelvinTo authored Dec 21, 2024
2 parents 85c7245 + 10233ec commit 27b7acb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/webpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ jobs:
node-version: '16'

- run: npm i -g yarn
- run: yarn global add webpack-cli
- run: yarn global add webpack-cli@5.1.4
- run: mkdir -p webpack; cd webpack; yarn add webpack webpack-cli || true
- run: $(yarn global bin)/webpack-cli -c .webpack/config.js
13 changes: 8 additions & 5 deletions util/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 27b7acb

Please sign in to comment.