diff --git a/CHANGES.md b/CHANGES.md index 0457d00..9013712 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ Known issues: ## not yet released +## 1.8.3 + +- [issue #450] Fix `log.info(null)` crash that resulted from #426 in v1.8.2. + + ## 1.8.2 - [issue #449] Bump dtrace-provider dep to 0.7.0 to help avoid deprecation @@ -26,7 +31,7 @@ Known issues: ## 1.8.0 Note: *Bad release.* An addition in this release broke 'rotating-file' usage. -Use 1.8.1 instead. +Use 1.8.1 or later. - [issue #370] Fix `bunyan -p ...` (i.e. DTrace integration) on node 4.x and 5.x. diff --git a/bin/bunyan b/bin/bunyan index 6f2c101..0f3f412 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -11,7 +11,7 @@ * vim: expandtab:ts=4:sw=4 */ -var VERSION = '1.8.2'; +var VERSION = '1.8.3'; var p = console.log; var util = require('util'); diff --git a/lib/bunyan.js b/lib/bunyan.js index 47a15d7..5442826 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -8,7 +8,7 @@ * vim: expandtab:ts=4:sw=4 */ -var VERSION = '1.8.2'; +var VERSION = '1.8.3'; /* * Bunyan log format version. This becomes the 'v' field on all log records. @@ -980,7 +980,7 @@ function mkLogEmitter(minLevel) { msgArgs[0] = util.inspect(msgArgs[0]); } else { // `log.(fields, msg, ...)` fields = args[0]; - if (args.length === 1 && fields.err && + if (fields && args.length === 1 && fields.err && fields.err instanceof Error) { msgArgs = [fields.err.message]; diff --git a/package.json b/package.json index 5b71d0b..53d3763 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bunyan", - "version": "1.8.2", + "version": "1.8.3", "description": "a JSON logging library for node.js services", "author": "Trent Mick (http://trentm.com)", "main": "./lib/bunyan.js", diff --git a/test/log.test.js b/test/log.test.js index 38a8996..6441463 100644 --- a/test/log.test.js +++ b/test/log.test.js @@ -239,13 +239,33 @@ test('log.info(, )', function (t) { t.end(); }); -test('log.info()', function (t) { - var e = new Error('boom'); + +/* + * By accident (starting with trentm/node-bunyan#85 in bunyan@0.23.0), + * log.info(null, ...) + * was interpreted as `null` being the object of fields. It is gracefully + * handled, which is good. However, had I to do it again, I would have made + * that interpret `null` as the *message*, and no fields having been passed. + * I think it is baked now. It would take a major bunyan rev to change it, + * but I don't think it is worth it: passing `null` as the first arg isn't + * really an intended way to call these Bunyan methods for either case. + */ + +test('log.info(null)', function (t) { names.forEach(function (lvl) { - log3[lvl].call(log3, e); + log3[lvl].call(log3, null); var rec = catcher.records[catcher.records.length - 1]; - t.equal(rec.err.message, 'boom', - format('log.%s err.message: got %j', lvl, rec.err.message)); + t.equal(rec.msg, '', format('log.%s msg: got %j', lvl, rec.msg)); + }); + t.end(); +}); + +test('log.info(null, )', function (t) { + names.forEach(function (lvl) { + log3[lvl].call(log3, null, 'my message'); + var rec = catcher.records[catcher.records.length - 1]; + t.equal(rec.msg, 'my message', + format('log.%s msg: got %j', lvl, rec.msg)); }); t.end(); });