Skip to content

Commit

Permalink
Feature - optionally include Error.cause property (#2447)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandra Tudor <alexandra.tudor@hermes.com>
  • Loading branch information
lexctk and Alexandra Tudor authored Nov 1, 2024
1 parent 195e55c commit 201b6f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/winston/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions test/unit/winston/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});

0 comments on commit 201b6f1

Please sign in to comment.