From ee0cf8b2a4cb354857adc86a7af285aab317168d Mon Sep 17 00:00:00 2001 From: Alexandra Tudor Date: Wed, 29 May 2024 14:20:09 +0200 Subject: [PATCH] Feature - optionally include Error.cause property --- lib/winston/logger.js | 1 + test/unit/winston/logger.test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/winston/logger.js b/lib/winston/logger.js index 5f8758c89..adc2ee589 100644 --- a/lib/winston/logger.js +++ b/lib/winston/logger.js @@ -248,6 +248,7 @@ class Logger extends Transform { if (meta.message) info.message = `${info.message} ${meta.message}`; if (meta.stack) info.stack = meta.stack; + if (meta.cause) info.cause = meta.cause; this.write(info); return this; diff --git a/test/unit/winston/logger.test.js b/test/unit/winston/logger.test.js index 83504f594..48ff644eb 100755 --- a/test/unit/winston/logger.test.js +++ b/test/unit/winston/logger.test.js @@ -1016,6 +1016,19 @@ describe('Logger Instance', function () { logger.log('info', '%d%% such %s %j', 100, 'wow', {much: 'javascript'}, {thisIsMeta: true}); }); + + it(`.log(level, new Error()) creates info with error cause`, function (done) { + const errCause = new Error("error cause"); + const err = new Error('test', { cause: errCause }); + const logger = helpers.createLogger(function (info) { + assume(info).instanceOf(Error); + assume(info).equals(err); + assume(info.cause).equals(errCause) + done(); + }); + + logger.log('info', err); + }); }); }); });