Skip to content

Commit

Permalink
Feature - optionally include Error.cause property
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra Tudor committed May 29, 2024
1 parent c63a5ad commit ee0cf8b
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 ee0cf8b

Please sign in to comment.