From 09742317fd6e85313f5616008a2f879cda0455cf Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Fri, 26 Aug 2016 00:01:04 -0700 Subject: [PATCH] Ensure `log.info({err: err})` results in a "msg" value, just like `log.info(err)` Fixes #426 --- CHANGES.md | 3 ++- lib/bunyan.js | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a08b1df..4d7c67a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,8 @@ Known issues: ## 1.8.2 (not yet released) -(nothing yet) +- [issue #426] Ensure `log.info({err: err})` results in a "msg" value, just + like `log.info(err)`. ## 1.8.1 diff --git a/lib/bunyan.js b/lib/bunyan.js index c595b2b..0817054 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -980,7 +980,13 @@ function mkLogEmitter(minLevel) { msgArgs[0] = util.inspect(msgArgs[0]); } else { // `log.(fields, msg, ...)` fields = args[0]; - msgArgs = Array.prototype.slice.call(args, 1); + if (args.length === 1 && fields.err + && fields.err instanceof Error) + { + msgArgs = [fields.err.message]; + } else { + msgArgs = Array.prototype.slice.call(args, 1); + } } // Build up the record object.