Skip to content

Commit 8c11772

Browse files
committed
Do not write undefined properties.
1 parent 7233a84 commit 8c11772

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pino.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ function pino (opts, stream) {
9999
data += ',"type":"Error","stack":' + stringify(obj.stack) + '}'
100100
} else {
101101
for (var key in obj) {
102-
data += ',"' + key + '":' + stringify(obj[key])
102+
if (obj[key]) {
103+
data += ',"' + key + '":' + stringify(obj[key])
104+
}
103105
}
104106
data += '}'
105107
}

test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,22 @@ test('set the level via constructor', function (t) {
206206
instance.error('this is an error')
207207
instance.fatal('this is fatal')
208208
})
209+
210+
test('set undefined properties', function (t) {
211+
t.plan(2)
212+
213+
var instance = pino(sink(function (chunk, enc, cb) {
214+
t.ok(Date.parse(chunk.time) <= new Date(), 'time is greater than Date.now()')
215+
delete chunk.time
216+
t.deepEqual(chunk, {
217+
pid: pid,
218+
hostname: hostname,
219+
level: 30,
220+
hello: 'world',
221+
v: 0
222+
})
223+
cb()
224+
}))
225+
226+
instance.info({ hello: 'world', property: undefined })
227+
})

0 commit comments

Comments
 (0)