diff --git a/pino.js b/pino.js index adfb7af65..b5689f5d6 100644 --- a/pino.js +++ b/pino.js @@ -99,7 +99,9 @@ function pino (opts, stream) { data += ',"type":"Error","stack":' + stringify(obj.stack) + '}' } else { for (var key in obj) { - data += ',"' + key + '":' + stringify(obj[key]) + if (obj[key]) { + data += ',"' + key + '":' + stringify(obj[key]) + } } data += '}' } diff --git a/test.js b/test.js index d5993191c..b522d842a 100644 --- a/test.js +++ b/test.js @@ -206,3 +206,22 @@ test('set the level via constructor', function (t) { instance.error('this is an error') instance.fatal('this is fatal') }) + +test('set undefined properties', function (t) { + t.plan(2) + + var instance = pino(sink(function (chunk, enc, cb) { + t.ok(Date.parse(chunk.time) <= new Date(), 'time is greater than Date.now()') + delete chunk.time + t.deepEqual(chunk, { + pid: pid, + hostname: hostname, + level: 30, + hello: 'world', + v: 0 + }) + cb() + })) + + instance.info({ hello: 'world', property: undefined }) +})