From 8c11772f3826ea645e8fada0a0bf8d8e45fbf3cf Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sat, 5 Mar 2016 18:34:32 +0100 Subject: [PATCH] Do not write undefined properties. --- pino.js | 4 +++- test.js | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 }) +})