Skip to content

Commit

Permalink
Merge pull request #15 from mcollina/better-serialization
Browse files Browse the repository at this point in the history
better serialization
  • Loading branch information
David Mark Clements committed Mar 21, 2016
2 parents ed4c391 + eaffb33 commit 9fd3c68
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
6 changes: 6 additions & 0 deletions benchmarks/multiArg.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ var run = bench([
}
setImmediate(cb)
},
function benchPinoInterpolate (cb) {
for (var i = 0; i < max; i++) {
plog.info('hello %s', 'world')
}
setImmediate(cb)
},
function benchBunyanInterpolateAll (cb) {
for (var i = 0; i < max; i++) {
blog.info('hello %s %j %d', 'world', {obj: true}, 4)
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@
"dependencies": {
"chalk": "^1.1.1",
"core-util-is": "^1.0.2",
"fast-json-parse": "^1.0.0",
"json-stringify-safe": "^5.0.1",
"quick-format": "^1.0.0",
"fast-safe-stringify": "^1.0.4",
"quick-format": "^2.0.0",
"split2": "^2.0.1"
}
}
9 changes: 5 additions & 4 deletions pino.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

var stringifySafe = require('json-stringify-safe')
var stringifySafe = require('fast-safe-stringify')
var format = require('quick-format')
var os = require('os')
var pid = process.pid
Expand All @@ -23,7 +23,8 @@ function pino (opts, stream) {
stream = stream || process.stdout
opts = opts || {}
var slowtime = opts.slowtime
var stringify = opts.safe !== false ? stringifySafe : JSON.stringify
var safe = opts.safe !== false
var stringify = safe ? stringifySafe : JSON.stringify
var name = opts.name
var level = opts.level
var funcs = {}
Expand Down Expand Up @@ -80,7 +81,7 @@ function pino (opts, stream) {
}
len = params.length = arguments.length - base
if (len > 1) {
msg = format(params)
msg = format(params, safe ? null : {lowres: true})
} else if (len) {
msg = params[0]
}
Expand Down Expand Up @@ -120,7 +121,7 @@ function pino (opts, stream) {
'"level":' + level + ',' +
(msg === undefined ? '' : '"msg":"' + (msg && msg.toString()) + '",') +
'"time":' + (slowtime ? '"' + (new Date()).toISOString() + '"' : Date.now()) + ',' +
'"v":' + 0
'"v":' + 1
}
}

Expand Down
26 changes: 13 additions & 13 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function check (t, chunk, level, msg) {
hostname: hostname,
level: level,
msg: msg,
v: 0
v: 1
})
}

Expand All @@ -48,7 +48,7 @@ function levelTest (name, level) {
hostname: hostname,
level: level,
hello: 'world',
v: 0
v: 1
})
}))

Expand All @@ -67,7 +67,7 @@ function levelTest (name, level) {
level: level,
msg: 'a string',
hello: 'world',
v: 0
v: 1
})
}))

Expand Down Expand Up @@ -98,7 +98,7 @@ function levelTest (name, level) {
type: 'Error',
msg: err.message,
stack: err.stack,
v: 0
v: 1
})
cb()
}))
Expand All @@ -118,7 +118,7 @@ function levelTest (name, level) {
level: level,
msg: 'hello world',
hello: 'world',
v: 0
v: 1
})
}))

Expand Down Expand Up @@ -202,7 +202,7 @@ test('set the name', function (t) {
level: 60,
name: 'hello',
msg: 'this is fatal',
v: 0
v: 1
})
cb()
}))
Expand Down Expand Up @@ -241,7 +241,7 @@ test('set undefined properties', function (t) {
hostname: hostname,
level: 30,
hello: 'world',
v: 0
v: 1
})
cb()
}))
Expand All @@ -260,7 +260,7 @@ test('set properties defined in the prototype chain', function (t) {
hostname: hostname,
level: 30,
hello: 'world',
v: 0
v: 1
})
cb()
}))
Expand All @@ -286,7 +286,7 @@ test('http request support', function (t) {
hostname: hostname,
level: 30,
msg: 'my request',
v: 0,
v: 1,
req: {
method: originalReq.method,
url: originalReq.url,
Expand Down Expand Up @@ -328,7 +328,7 @@ test('http request support via serializer', function (t) {
hostname: hostname,
level: 30,
msg: 'my request',
v: 0,
v: 1,
req: {
method: originalReq.method,
url: originalReq.url,
Expand Down Expand Up @@ -366,7 +366,7 @@ test('http response support', function (t) {
hostname: hostname,
level: 30,
msg: 'my response',
v: 0,
v: 1,
res: {
statusCode: originalRes.statusCode,
header: originalRes._header
Expand Down Expand Up @@ -405,7 +405,7 @@ test('http response support via a serializer', function (t) {
hostname: hostname,
level: 30,
msg: 'my response',
v: 0,
v: 1,
res: {
statusCode: originalRes.statusCode,
header: originalRes._header
Expand Down Expand Up @@ -454,7 +454,7 @@ test('http request support via serializer in a child', function (t) {
hostname: hostname,
level: 30,
msg: 'my request',
v: 0,
v: 1,
req: {
method: originalReq.method,
url: originalReq.url,
Expand Down

0 comments on commit 9fd3c68

Please sign in to comment.