Skip to content

Commit 201b6f1

Browse files
lexctkAlexandra Tudor
and
Alexandra Tudor
authoredNov 1, 2024··
Feature - optionally include Error.cause property (#2447)
Co-authored-by: Alexandra Tudor <alexandra.tudor@hermes.com>
1 parent 195e55c commit 201b6f1

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed
 

Diff for: ‎lib/winston/logger.js

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ class Logger extends Transform {
248248

249249
if (meta.message) info.message = `${info.message} ${meta.message}`;
250250
if (meta.stack) info.stack = meta.stack;
251+
if (meta.cause) info.cause = meta.cause;
251252

252253
this.write(info);
253254
return this;

Diff for: ‎test/unit/winston/logger.test.js

+13
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,19 @@ describe('Logger Instance', function () {
10161016

10171017
logger.log('info', '%d%% such %s %j', 100, 'wow', {much: 'javascript'}, {thisIsMeta: true});
10181018
});
1019+
1020+
it(`.log(level, new Error()) creates info with error cause`, function (done) {
1021+
const errCause = new Error("error cause");
1022+
const err = new Error('test', { cause: errCause });
1023+
const logger = helpers.createLogger(function (info) {
1024+
assume(info).instanceOf(Error);
1025+
assume(info).equals(err);
1026+
assume(info.cause).equals(errCause)
1027+
done();
1028+
});
1029+
1030+
logger.log('info', err);
1031+
});
10191032
});
10201033
});
10211034
});

0 commit comments

Comments
 (0)
Please sign in to comment.