From a903bd058e40203689a88b8add609ba0fcb4c68d Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 28 Jul 2023 13:21:06 -0400 Subject: [PATCH 01/13] chore(lodash): adding lodash as a dependency to leverage cloneDeep --- package-lock.json | 13 ++++++------- package.json | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 943aae255..089cf1ab2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@dabh/diagnostics": "^2.0.2", "async": "^3.2.3", "is-stream": "^2.0.0", + "lodash": "^4.17.21", "logform": "^2.4.0", "one-time": "^1.0.0", "readable-stream": "^3.4.0", @@ -41,7 +42,7 @@ "winston-compat": "^0.1.5" }, "engines": { - "node": ">= 16.0.0" + "node": ">= 12.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -4681,9 +4682,8 @@ }, "node_modules/lodash": { "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "resolved": "https://artifactory.cloud.capitalone.com:443/artifactory/api/npm/npm-internalfacing/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash.debounce": { "version": "4.0.8", @@ -10565,9 +10565,8 @@ }, "lodash": { "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "resolved": "https://artifactory.cloud.capitalone.com:443/artifactory/api/npm/npm-internalfacing/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash.debounce": { "version": "4.0.8", diff --git a/package.json b/package.json index ad68706f2..66a156f7a 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "@colors/colors": "1.5.0", "async": "^3.2.3", "is-stream": "^2.0.0", + "lodash": "^4.17.21", "logform": "^2.4.0", "one-time": "^1.0.0", "readable-stream": "^3.4.0", From 89db297a832b19e82af4b97fe83a1cea566b6b29 Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 28 Jul 2023 13:43:56 -0400 Subject: [PATCH 02/13] feat(cloneDeep): added a utility function that creates deep copies of an object --- lib/winston/common.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/winston/common.js b/lib/winston/common.js index ac8e99d49..b91407e7b 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -8,6 +8,7 @@ 'use strict'; const { format } = require('util'); +const _ = require('lodash'); /** * Set of simple deprecation notices and a way to expose them for a set of @@ -44,3 +45,15 @@ exports.warn = { }); } }; + + +exports.dataUtils = { + /** + * Creates a deep copy of an object + * @param {Object} obj The object to clone + * @returns {Object} A deep copy of the parameter object + */ + cloneObject(obj) { + return _.cloneDeep(obj); + }, +} From be8e67aa00fcc641017dfaf2bb0fce632a0255b3 Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 28 Jul 2023 13:55:21 -0400 Subject: [PATCH 03/13] feat(logger.js): implement deep copy where data mutation occurs in logger functions --- lib/winston/logger.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/winston/logger.js b/lib/winston/logger.js index 5f8758c89..fa0d1192b 100644 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -15,7 +15,7 @@ const ExceptionHandler = require('./exception-handler'); const RejectionHandler = require('./rejection-handler'); const LegacyTransportStream = require('winston-transport/legacy'); const Profiler = require('./profiler'); -const { warn } = require('./common'); +const { warn, dataUtils } = require('./common'); const config = require('./config'); /** @@ -205,6 +205,7 @@ class Logger extends Transform { */ /* eslint-enable valid-jsdoc */ log(level, msg, ...splat) { + let msgCopy; // eslint-disable-line max-params // Optimize for the hotpath of logging JSON literals if (arguments.length === 1) { @@ -220,15 +221,16 @@ class Logger extends Transform { // Slightly less hotpath, but worth optimizing for. if (arguments.length === 2) { if (msg && typeof msg === 'object') { - msg[LEVEL] = msg.level = level; - this._addDefaultMeta(msg); - this.write(msg); + msgCopy = dataUtils.cloneObject(msg); + msgCopy[LEVEL] = msg.level = level; + this._addDefaultMeta(msgCopy); + this.write(msgCopy); return this; } - msg = { [LEVEL]: level, level, message: msg }; - this._addDefaultMeta(msg); - this.write(msg); + msgCopy = { [LEVEL]: level, level, message: msg }; + this._addDefaultMeta(msgCopy); + this.write(msgCopy); return this; } @@ -243,7 +245,7 @@ class Logger extends Transform { [LEVEL]: level, [SPLAT]: splat, level, - message: msg + message: dataUtils.cloneObject(msg) }); if (meta.message) info.message = `${info.message} ${meta.message}`; From 19ea2c91415bcb5b6164438a16971106d5c29526 Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 28 Jul 2023 13:58:50 -0400 Subject: [PATCH 04/13] feat(create-logger.js): implement deep copy where data mutation occurs in create-logger --- lib/winston/create-logger.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/winston/create-logger.js b/lib/winston/create-logger.js index e868aeaad..54085445c 100644 --- a/lib/winston/create-logger.js +++ b/lib/winston/create-logger.js @@ -10,6 +10,7 @@ const { LEVEL } = require('triple-beam'); const config = require('./config'); const Logger = require('./logger'); +const { dataUtils } = require('./common'); const debug = require('@dabh/diagnostics')('winston:create-logger'); function isLevelEnabledFunctionName(level) { @@ -75,7 +76,7 @@ module.exports = function (opts = {}) { // Optimize the hot-path which is the single object. if (args.length === 1) { const [msg] = args; - const info = msg && msg.message && msg || { message: msg }; + const info = msg && msg.message && dataUtils.cloneObject(msg) || { message: msg }; info.level = info[LEVEL] = level; self._addDefaultMeta(info); self.write(info); From 68d6facf75cd54345d639a30bbbaded3189039d5 Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 4 Aug 2023 15:21:57 -0400 Subject: [PATCH 05/13] fix(logger.js): shallow copy in case where there are 2 parameters --- lib/winston/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/winston/logger.js b/lib/winston/logger.js index fa0d1192b..dc25b7723 100644 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -222,7 +222,7 @@ class Logger extends Transform { if (arguments.length === 2) { if (msg && typeof msg === 'object') { msgCopy = dataUtils.cloneObject(msg); - msgCopy[LEVEL] = msg.level = level; + msgCopy[LEVEL] = msgCopy.level = level; this._addDefaultMeta(msgCopy); this.write(msgCopy); return this; From d484d279e5ab064c513540ae6760550534320f28 Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 4 Aug 2023 16:08:53 -0400 Subject: [PATCH 06/13] fix(common.js): handle error case by creating a new error since errors cannot be copied --- lib/winston/common.js | 21 ++++++++++++++++++--- test/unit/winston/logger.test.js | 10 ++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/winston/common.js b/lib/winston/common.js index b91407e7b..7e8273355 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -50,10 +50,25 @@ exports.warn = { exports.dataUtils = { /** * Creates a deep copy of an object - * @param {Object} obj The object to clone + * @param {Object | string} data The data to clone * @returns {Object} A deep copy of the parameter object */ - cloneObject(obj) { - return _.cloneDeep(obj); + cloneObject(data) { + const isError = Object.prototype.toString.call(data) === "[object Error]"; + const isObject = typeof data === 'object'; + + if (isError) { + const nextErr = new Error(data.message); + + nextErr.stack = data.stack; + return nextErr; + } else if (isObject) { + const nextObj = _.cloneDeep(data); + + return nextObj; + } + + // Assume the primitive case + return data; }, } diff --git a/test/unit/winston/logger.test.js b/test/unit/winston/logger.test.js index 83504f594..2b39a425a 100755 --- a/test/unit/winston/logger.test.js +++ b/test/unit/winston/logger.test.js @@ -768,11 +768,12 @@ describe('Logger Instance', function () { logger.info(null); }); - it('.info(new Error()) uses Error instance as info', function (done) { + it('.info(new Error()) uses Error instance data as info', function (done) { const err = new Error('test'); const logger = helpers.createLogger(function (info) { assume(info).instanceOf(Error); - assume(info).equals(err); + assume(info.message).equals(err.message); + assume(info.stack).equals(err.stack); done(); }); @@ -955,11 +956,12 @@ describe('Logger Instance', function () { logger.log('info', null); }); - it(`.log(level, new Error()) uses Error instance as info`, function (done) { + it(`.log(level, new Error()) uses Error instance data as info`, function (done) { const err = new Error('test'); const logger = helpers.createLogger(function (info) { assume(info).instanceOf(Error); - assume(info).equals(err); + assume(info.message).equals(err.message); + assume(info.stack).equals(err.stack); done(); }); From 38149d4a19d8f4312d90a9a24e1e4c8623c3459d Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 4 Aug 2023 16:39:53 -0400 Subject: [PATCH 07/13] fix(logger.js): handle the case where there is a single parameter --- lib/winston/logger.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/winston/logger.js b/lib/winston/logger.js index dc25b7723..26435d53b 100644 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -212,9 +212,10 @@ class Logger extends Transform { // Yo dawg, I heard you like levels ... seriously ... // In this context the LHS `level` here is actually the `info` so read // this as: info[LEVEL] = info.level; - level[LEVEL] = level.level; - this._addDefaultMeta(level); - this.write(level); + msgCopy = dataUtils.cloneObject(level); + msgCopy[LEVEL] = level.level; + this._addDefaultMeta(msgCopy); + this.write(msgCopy); return this; } From f708deb9b49dbf050719e3b257b57dfefa5bdedd Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 4 Aug 2023 16:49:30 -0400 Subject: [PATCH 08/13] refactor(common.js): update error block to use object.assign to ensure custom properties are not lost. Updated unit test to check properties instead of instance since we are not modifying the original data --- lib/winston/common.js | 10 ++++++---- test/unit/winston/logger.test.js | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/winston/common.js b/lib/winston/common.js index 7e8273355..c036f3dda 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -54,13 +54,15 @@ exports.dataUtils = { * @returns {Object} A deep copy of the parameter object */ cloneObject(data) { - const isError = Object.prototype.toString.call(data) === "[object Error]"; + const isError = Object.prototype.toString.call(data) === '[object Error]'; const isObject = typeof data === 'object'; if (isError) { - const nextErr = new Error(data.message); + let nextErr = new Error(data.message); nextErr.stack = data.stack; + Object.assign(nextErr, data); + return nextErr; } else if (isObject) { const nextObj = _.cloneDeep(data); @@ -70,5 +72,5 @@ exports.dataUtils = { // Assume the primitive case return data; - }, -} + } +}; diff --git a/test/unit/winston/logger.test.js b/test/unit/winston/logger.test.js index 2b39a425a..7d6f1de56 100755 --- a/test/unit/winston/logger.test.js +++ b/test/unit/winston/logger.test.js @@ -695,13 +695,15 @@ describe('Logger Instance', function () { // TODO: Revisit to improve these describe('Logging non-primitive data types', function () { describe('.log', function () { - it(`.log(new Error()) uses Error instance as info`, function (done) { + it(`.log(new Error()) uses Error instance data as info`, function (done) { const err = new Error('test'); err.level = 'info'; const logger = helpers.createLogger(function (info) { assume(info).instanceOf(Error); - assume(info).equals(err); + assume(info.message).equals(err.message); + assume(info.stack).equals(err.stack); + assume(info.level).equals(err.level); done(); }); From 451061e38c916a3f505138ff8d93290414eea4c3 Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 4 Aug 2023 16:49:59 -0400 Subject: [PATCH 09/13] refactor(common.js): rm lodash --- lib/winston/common.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/winston/common.js b/lib/winston/common.js index c036f3dda..23a10514b 100644 --- a/lib/winston/common.js +++ b/lib/winston/common.js @@ -8,7 +8,6 @@ 'use strict'; const { format } = require('util'); -const _ = require('lodash'); /** * Set of simple deprecation notices and a way to expose them for a set of @@ -65,9 +64,7 @@ exports.dataUtils = { return nextErr; } else if (isObject) { - const nextObj = _.cloneDeep(data); - - return nextObj; + return Object.assign({}, data); } // Assume the primitive case From d297e90cf7378341d194456b532c77564eb21bce Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 4 Aug 2023 16:50:41 -0400 Subject: [PATCH 10/13] Revert "chore(lodash): adding lodash as a dependency to leverage cloneDeep" This reverts commit a903bd058e40203689a88b8add609ba0fcb4c68d. --- package-lock.json | 13 +++++++------ package.json | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 089cf1ab2..943aae255 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,6 @@ "@dabh/diagnostics": "^2.0.2", "async": "^3.2.3", "is-stream": "^2.0.0", - "lodash": "^4.17.21", "logform": "^2.4.0", "one-time": "^1.0.0", "readable-stream": "^3.4.0", @@ -42,7 +41,7 @@ "winston-compat": "^0.1.5" }, "engines": { - "node": ">= 12.0.0" + "node": ">= 16.0.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -4682,8 +4681,9 @@ }, "node_modules/lodash": { "version": "4.17.21", - "resolved": "https://artifactory.cloud.capitalone.com:443/artifactory/api/npm/npm-internalfacing/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "node_modules/lodash.debounce": { "version": "4.0.8", @@ -10565,8 +10565,9 @@ }, "lodash": { "version": "4.17.21", - "resolved": "https://artifactory.cloud.capitalone.com:443/artifactory/api/npm/npm-internalfacing/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "lodash.debounce": { "version": "4.0.8", diff --git a/package.json b/package.json index 66a156f7a..ad68706f2 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,6 @@ "@colors/colors": "1.5.0", "async": "^3.2.3", "is-stream": "^2.0.0", - "lodash": "^4.17.21", "logform": "^2.4.0", "one-time": "^1.0.0", "readable-stream": "^3.4.0", From 041b115fcaa91468bea33cc2499486f4a66ae4dd Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Fri, 4 Aug 2023 17:52:59 -0400 Subject: [PATCH 11/13] test(errors.test.js): added test to ensure error objects passed in are not mutated --- test/unit/formats/errors.test.js | 44 ++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/test/unit/formats/errors.test.js b/test/unit/formats/errors.test.js index 400de910a..d64958705 100644 --- a/test/unit/formats/errors.test.js +++ b/test/unit/formats/errors.test.js @@ -35,14 +35,19 @@ function assumeExpectedInfo(info, target = {}) { }); } +function assumeNonMutatedObject(originalObject) { + assume(originalObject[LEVEL]).equals(undefined); +} + describe('format.errors (integration)', function () { it('logger.log(level, error)', (done) => { const logger = helpers.createLogger(function (info) { assumeExpectedInfo(info); done(); }, format.errors()); + const err = new Error('Errors lack .toJSON() lulz'); - logger.log('info', new Error('Errors lack .toJSON() lulz')); + logger.log('info', err); }); it('logger.log(level, error) [custom error properties]', (done) => { @@ -51,7 +56,7 @@ describe('format.errors (integration)', function () { something: true, wut: 'another string' }); - + assumeNonMutatedObject(err); done(); }, format.errors()); @@ -67,13 +72,15 @@ describe('format.errors (integration)', function () { thisIsMeta: true, anyValue: 'a string' }; + const err = new Error('Errors lack .toJSON() lulz'); const logger = helpers.createLogger(function (info) { assumeExpectedInfo(info, meta); + assumeNonMutatedObject(err); done(); }, format.errors()); - logger.log('info', new Error('Errors lack .toJSON() lulz'), meta); + logger.log('info', err, meta); }); it('logger.log(level, error, meta) [custom error properties]', (done) => { @@ -87,6 +94,7 @@ describe('format.errors (integration)', function () { something: true, wut: 'another string' }, meta)); + assumeNonMutatedObject(err); done(); }, format.errors()); @@ -103,14 +111,14 @@ describe('format.errors (integration)', function () { assumeExpectedInfo(info, { message: 'Caught error: Errors lack .toJSON() lulz' }); - + assumeNonMutatedObject(err); done(); }, format.combine( format.errors(), format.printf(info => info.message) )); - - logger.log('info', 'Caught error:', new Error('Errors lack .toJSON() lulz')); + const err = new Error('Errors lack .toJSON() lulz'); + logger.log('info', 'Caught error:', err); }); it('logger.log(level, msg, meta) [custom error properties]', (done) => { @@ -125,7 +133,7 @@ describe('format.errors (integration)', function () { something: true, wut: 'another string' }); - + assumeNonMutatedObject(err); done(); }, format.combine( format.errors(), @@ -138,10 +146,12 @@ describe('format.errors (integration)', function () { it('logger.(error)', (done) => { const logger = helpers.createLogger(function (info) { assumeExpectedInfo(info); + assumeNonMutatedObject(err); done(); }, format.errors()); + const err = new Error('Errors lack .toJSON() lulz') - logger.info(new Error('Errors lack .toJSON() lulz')); + logger.info(err); }); it('logger.(error) [custom error properties]', (done) => { @@ -150,7 +160,7 @@ describe('format.errors (integration)', function () { something: true, wut: 'another string' }); - + assumeNonMutatedObject(err); done(); }, format.errors()); @@ -169,10 +179,11 @@ describe('format.errors (integration)', function () { const logger = helpers.createLogger(function (info) { assumeExpectedInfo(info, meta); + assumeNonMutatedObject(err); done(); }, format.errors()); - - logger.info(new Error('Errors lack .toJSON() lulz'), meta); + const err = new Error('Errors lack .toJSON() lulz'); + logger.info(err, meta); }); it('logger.(error, meta) [custom error properties]', (done) => { @@ -186,7 +197,7 @@ describe('format.errors (integration)', function () { something: true, wut: 'another string' }, meta)); - + assumeNonMutatedObject(err); done(); }, format.errors()); @@ -202,14 +213,15 @@ describe('format.errors (integration)', function () { assumeExpectedInfo(info, { message: 'Caught error: Errors lack .toJSON() lulz' }); - + assumeNonMutatedObject(err); done(); }, format.combine( format.errors(), format.printf(info => info.message) )); + const err = new Error('Errors lack .toJSON() lulz'); - logger.info('Caught error:', new Error('Errors lack .toJSON() lulz')); + logger.info('Caught error:', err); }); it('logger.(msg, meta) [custom error properties]', (done) => { @@ -224,7 +236,7 @@ describe('format.errors (integration)', function () { something: true, wut: 'another string' }); - + assumeNonMutatedObject(err); done(); }, format.combine( format.errors(), @@ -264,4 +276,4 @@ describe('format.errors (integration)', function () { throw err; }).catch(logger.error.bind(logger)); }); -}); + }); From 5a368152106ecc33cf6426f93f1ad75fafe82833 Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Mon, 14 Aug 2023 16:41:44 -0400 Subject: [PATCH 12/13] test(logger.test.js): added test to ensure non-primitive objects passed in are not mutated --- .torchignore | 1 + test/unit/winston/logger.test.js | 82 +++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 .torchignore diff --git a/.torchignore b/.torchignore new file mode 100644 index 000000000..a8c23e333 --- /dev/null +++ b/.torchignore @@ -0,0 +1 @@ +pattern: asymmetric-private-key diff --git a/test/unit/winston/logger.test.js b/test/unit/winston/logger.test.js index 7d6f1de56..6d5209ac2 100755 --- a/test/unit/winston/logger.test.js +++ b/test/unit/winston/logger.test.js @@ -15,7 +15,7 @@ const util = require('util'); const { EOL } = require('os'); const isStream = require('is-stream'); const stdMocks = require('std-mocks'); -const { MESSAGE, SPLAT } = require('triple-beam'); +const { MESSAGE, SPLAT, LEVEL } = require('triple-beam'); const winston = require('../../../lib/winston'); const TransportStream = require('winston-transport'); const format = require('../../../lib/winston').format; @@ -749,6 +749,46 @@ describe('Logger Instance', function () { logger.info('Hello', {label: 'world'}); logger.info('Hello %d', 100, {label: 'world'}); }); + + it(`.log(level, object) does not mutate input`, function (done) { + const data = { message: 'hello' }; + + const logger = helpers.createLogger(function (info) { + assume(info[LEVEL]).equals('info'); + assume(info.message).equals('hello'); + assume(data[LEVEL]).equals(undefined); + assume(data).deep.equal({ message: 'hello' }); + done(); + }); + + logger.log('info', data); + }); + + it(`.log(level, array) does not mutate input`, function (done) { + const data = ['one', 'two', 'three']; + + const logger = helpers.createLogger(function (info) { + assume(info[LEVEL]).equals('info'); + assume(data[LEVEL]).equals(undefined); + assume(data).deep.equal(['one', 'two', 'three']); + done(); + }); + + logger.log('info', data); + }); + + it(`.log(level, object, splat) does not mutate input`, function (done) { + const data = { message: 'hello' }; + + const logger = helpers.createLogger(function (info) { + assume(info[LEVEL]).equals('info'); + assume(data[LEVEL]).equals(undefined); + assume(data).deep.equal({ message: 'hello' }); + done(); + }); + + logger.log('info', data, { label: 'test' }); + }); }); describe('.info', function () { @@ -782,6 +822,46 @@ describe('Logger Instance', function () { logger.info(err); }); + it(`.info(object) does not mutate input`, function (done) { + const data = { message: 'hello' }; + + const logger = helpers.createLogger(function (info) { + assume(info.message).equals('hello'); + assume(info[LEVEL]).equals('info'); + assume(data).deep.equal({ message: 'hello' }); + assume(data[LEVEL]).equals(undefined); + done(); + }); + + logger.info(data); + }); + + it(`.info(array) does not mutate input`, function (done) { + const data = ['one', 'two', 'three']; + + const logger = helpers.createLogger(function (info) { + assume(info[LEVEL]).equals('info'); + assume(data).deep.equal(['one', 'two', 'three']); + assume(data[LEVEL]).equals(undefined); + done(); + }); + + logger.info(data); + }); + + it(`.info(array) does not mutate input`, function (done) { + const data = { message: ['one', 'two', 'three'] }; + + const logger = helpers.createLogger(function (info) { + assume(info[LEVEL]).equals('info'); + assume(data).deep.equal({ message: ['one', 'two', 'three'] }); + assume(data[LEVEL]).equals(undefined); + done(); + }); + + logger.info(data); + }); + // TODO: This test needs finished or removed it.skip(`.info('any string', new Error())`, function (done) { const err = new Error('test'); From c112410e09e2d58b9aa246d0027fc3ee2e44abab Mon Sep 17 00:00:00 2001 From: Matt Russo Date: Tue, 29 Aug 2023 13:10:36 -0400 Subject: [PATCH 13/13] chore(cfg): rm config --- .torchignore | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .torchignore diff --git a/.torchignore b/.torchignore deleted file mode 100644 index a8c23e333..000000000 --- a/.torchignore +++ /dev/null @@ -1 +0,0 @@ -pattern: asymmetric-private-key