X-Git-Url: https://git.squeep.com/?p=squeep-logger-json-console;a=blobdiff_plain;f=lib%2Flogger.js;fp=lib%2Flogger.js;h=6cc4a2b4f30065b6d51e41de253d2267a780ee95;hp=3f336ab4c7121d17fbeaca6eacfee45bc678c043;hb=48e12e20d03a60384830773c2ee5f37db556a894;hpb=1f557bcdd06dfdba6ce7485bd6307db3359dcb08 diff --git a/lib/logger.js b/lib/logger.js index 3f336ab..6cc4a2b 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -3,7 +3,7 @@ const jsonReplacers = require('./json-replacers'); const dataSanitizers = require('./data-sanitizers'); -const nop = () => { /**/ }; +const nop = () => undefined; class Logger { /** @@ -94,7 +94,11 @@ class Logger { if (this.sanitizationNeeded(data)) { // Create copy of data so we are not changing anything important. - data = structuredClone(data); + try { + data = structuredClone(data); + } catch (e) { + data = JSON.parse(JSON.stringify(data, replacer)); + } this.sanitize(data); } @@ -150,7 +154,7 @@ class Logger { while (ancestors.length > 0 && ancestors.at(-1) !== this) { ancestors.pop(); } - if (ancestors.includes(value)) { // eslint-disable-line security/detect-object-injection + if (ancestors.includes(value)) { return '[Circular]'; } else { ancestors.push(value); @@ -158,7 +162,7 @@ class Logger { } return value; - } + }; } }