Skip to content

Commit

Permalink
Do not write undefined properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Mar 5, 2016
1 parent 7233a84 commit 8c11772
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 += '}'
}
Expand Down
19 changes: 19 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
})

0 comments on commit 8c11772

Please sign in to comment.