Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - optionally include Error.cause property #2447

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
});
});
});
});