From: Justin Wind Date: Wed, 22 Nov 2023 17:27:28 +0000 (-0800) Subject: fix ordering of replacing and de-cycling to work correctly in some situations X-Git-Tag: v3.0.1~1 X-Git-Url: http://git.squeep.com/?p=squeep-logger-json-console;a=commitdiff_plain;h=474f670442eb06faf9ed4f64e9cec39ea92b4259 fix ordering of replacing and de-cycling to work correctly in some situations --- diff --git a/lib/logger.js b/lib/logger.js index e11810e..3f336ab 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -94,7 +94,7 @@ class Logger { if (this.sanitizationNeeded(data)) { // Create copy of data so we are not changing anything important. - data = structuredClone(data, replacer); + data = structuredClone(data); this.sanitize(data); } @@ -140,8 +140,13 @@ class Logger { const ancestors = []; const loggerReplacers = this.jsonReplacers; return function cycleReplacer(key, value) { + loggerReplacers.every((replacer) => { + const oldValue = value; + value = replacer(key, value); + return oldValue === value; + }); if (typeof value === 'object' && value !== null) { - // this is object where key/value came from + // 'this' is object where key/value came from while (ancestors.length > 0 && ancestors.at(-1) !== this) { ancestors.pop(); } @@ -152,11 +157,6 @@ class Logger { } } - loggerReplacers.every((replacer) => { - const oldValue = value; - value = replacer(key, value); - return oldValue === value; - }); return value; } }