Ensure log.info({err: err}) results in a "msg" value, just like log.info(err)

Fixes #426
This commit is contained in:
Trent Mick 2016-08-26 00:01:04 -07:00
parent 876d3584b4
commit 09742317fd
2 changed files with 9 additions and 2 deletions

View file

@ -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

View file

@ -980,7 +980,13 @@ function mkLogEmitter(minLevel) {
msgArgs[0] = util.inspect(msgArgs[0]);
} else { // `log.<level>(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.