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

Merged
merged 1 commit into from
Nov 1, 2024
Merged
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 @@ -78,7 +78,7 @@
* @param {!Object} options - TODO: add param description.
* @returns {undefined}
*/
configure({

Check warning on line 81 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (16)

Method 'configure' has too many statements (24). Maximum allowed is 15

Check warning on line 81 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (16)

Method 'configure' has a complexity of 19. Maximum allowed is 11

Check warning on line 81 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (18)

Method 'configure' has too many statements (24). Maximum allowed is 15

Check warning on line 81 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (18)

Method 'configure' has a complexity of 19. Maximum allowed is 11

Check warning on line 81 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (20)

Method 'configure' has too many statements (24). Maximum allowed is 15

Check warning on line 81 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (20)

Method 'configure' has a complexity of 19. Maximum allowed is 11
silent,
format,
defaultMeta,
Expand Down Expand Up @@ -204,7 +204,7 @@
*
*/
/* eslint-enable valid-jsdoc */
log(level, msg, ...splat) {

Check warning on line 207 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (16)

Method 'log' has too many statements (27). Maximum allowed is 15

Check warning on line 207 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (16)

Method 'log' has a complexity of 13. Maximum allowed is 11

Check warning on line 207 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (18)

Method 'log' has too many statements (27). Maximum allowed is 15

Check warning on line 207 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (18)

Method 'log' has a complexity of 13. Maximum allowed is 11

Check warning on line 207 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (20)

Method 'log' has too many statements (27). Maximum allowed is 15

Check warning on line 207 in lib/winston/logger.js

View workflow job for this annotation

GitHub Actions / Tests (20)

Method 'log' has a complexity of 13. Maximum allowed is 11
// eslint-disable-line max-params
// Optimize for the hotpath of logging JSON literals
if (arguments.length === 1) {
Expand Down Expand Up @@ -248,6 +248,7 @@

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