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

fix: append error cause when using logger.child() #2467

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -62,6 +62,7 @@ class Logger extends Transform {
if (info instanceof Error) {
infoClone.stack = info.stack;
infoClone.message = info.message;
infoClone.cause = info.cause;
}

logger.write(infoClone);
Expand Down
4 changes: 3 additions & 1 deletion test/unit/winston/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,8 @@ describe('Logger Instance', function () {
assume(msg.message).equals('dummy error');
assume(msg.stack).includes('logger.test.js');
assume(msg.service).equals('user-service');
assume(msg.cause.message).equals('dummy error cause');
assume(msg.cause.stack).includes('logger.test.js');
done();
});

Expand All @@ -908,7 +910,7 @@ describe('Logger Instance', function () {
});

const childLogger = logger.child({service: 'user-service'});
childLogger.error(Error('dummy error'));
childLogger.error(Error('dummy error', { cause: Error('dummy error cause') }));
});

it('defaultMeta() autobinds correctly', (done) => {
Expand Down