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); + }); }); }); });