From 4455189b77ed131a142fd38112745b8fdf141f45 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Sat, 27 Sep 2014 21:49:27 -0700 Subject: [PATCH] Include extra `err` fields in `bunyan` CLI output. Fixes #165. --- CHANGES.md | 6 +++++- bin/bunyan | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5c961ca..aa96ff9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,11 @@ Known issues: ## 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 diff --git a/bin/bunyan b/bin/bunyan index e3c5bd6..f449c83 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -938,7 +938,17 @@ function emitRecord(rec, line, opts, stylize) { } 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; }