From 67985077e77de230d8e57ca674299a2043a885c1 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 1 Feb 2022 11:24:04 +0100 Subject: [PATCH] fix(loggable): removed private properties from logs --- loopback/common/models/loggable.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/loopback/common/models/loggable.js b/loopback/common/models/loggable.js index 956762be2..28a6075d0 100644 --- a/loopback/common/models/loggable.js +++ b/loopback/common/models/loggable.js @@ -291,7 +291,8 @@ module.exports = function(Self) { * @param {*} properties Modified object properties */ function removeUnloggable(definition, properties) { - const propList = Object.keys(properties); + const objectCopy = Object.assign({}, properties); + const propList = Object.keys(objectCopy); const propDefs = new Map(); for (let property in definition.properties) { @@ -302,10 +303,15 @@ module.exports = function(Self) { for (let property of propList) { const propertyDef = propDefs.get(property); + const firstChar = property.substring(0, 1); + const isPrivate = firstChar == '$'; - if (!propertyDef) return; + if (isPrivate || !propertyDef) + delete properties[property]; - if (propertyDef.log === false) + if (!propertyDef) continue; + + if (propertyDef.log === false || isPrivate) delete properties[property]; else if (propertyDef.logValue === false) properties[property] = null;