Include extra err fields in bunyan CLI output.

Fixes #165.
This commit is contained in:
Trent Mick 2014-09-27 21:49:27 -07:00
parent bd149b924b
commit 4455189b77
2 changed files with 16 additions and 2 deletions

View file

@ -8,7 +8,11 @@ Known issues:
## bunyan 1.1.3 (not yet released) ## bunyan 1.1.3 (not yet released)
(nothing yet) - [issue #165] Include extra `err` fields in `bunyan` CLI output. Before
this change only the fields part of the typical node.js error stack
(err.stack, err.message, err.name) would be emitted, even though
the Bunyan *library* would typically include err.code and err.signal
in the raw JSON log record.
## bunyan 1.1.2 ## bunyan 1.1.2

View file

@ -938,7 +938,17 @@ function emitRecord(rec, line, opts, stylize) {
} }
if (rec.err && rec.err.stack) { if (rec.err && rec.err.stack) {
details.push(indent(rec.err.stack)); var err = rec.err
details.push(indent(err.stack));
delete err.message;
delete err.name;
delete err.stack;
// E.g. for extra 'foo' field on 'err', add 'err.foo' at
// top-level. This *does* have the potential to stomp on a
// literal 'err.foo' key.
Object.keys(err).forEach(function (k) {
rec['err.' + k] = err[k];
})
delete rec.err; delete rec.err;
} }