Skip to content

Commit

Permalink
Do not cause problems to turbofan (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jun 27, 2017
1 parent 517e78b commit 09d5990
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
27 changes: 27 additions & 0 deletions benchmarks/just-pino.bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

var bench = require('fastbench')
var pino = require('../')
var fs = require('fs')
var dest = fs.createWriteStream('/dev/null')
var plog = pino(dest)
delete require.cache[require.resolve('../')]
var plogExtreme = require('../')({extreme: true}, dest)
var max = 10

var run = bench([
function benchPino (cb) {
for (var i = 0; i < max; i++) {
plog.info('hello world')
}
setImmediate(cb)
},
function benchPinoExtreme (cb) {
for (var i = 0; i < max; i++) {
plogExtreme.info('hello world')
}
setImmediate(cb)
}
], 10000)

run(run)
2 changes: 1 addition & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function genLog (z) {
} else {
o = format(n, this.formatOpts)
}
} else if (p) {
} else if (p === 1) {
o = n[0]
}
this.write(m, o, z)
Expand Down
23 changes: 14 additions & 9 deletions pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,31 @@ Object.defineProperty(
)

function asJson (obj, msg, num) {
if (!msg && obj instanceof Error) {
msg = obj.message
// to catch both null and undefined
var objError = obj instanceof Error
if (!msg) {
if (objError) {
msg = obj.message
} else {
msg = undefined
}
}
var data = this._baseLog + this._lscache[num] + this.time()
// to catch both null and undefined
/* eslint-disable eqeqeq */
if (msg != undefined) {
if (msg !== undefined) {
data += this.messageKeyString + this.stringify('' + msg)
}
// we need the child bindings added to the output first so that logged
// objects can take precedence when JSON.parse-ing the resulting log line
data = data + this.chindings
var value
if (obj) {
if (obj.stack) {
if (obj !== undefined && obj !== null) {
var notHasOwnProperty = obj.hasOwnProperty === undefined
if (objError) {
data += ',"type":"Error","stack":' + this.stringify(obj.stack)
}
for (var key in obj) {
value = obj[key]
if ((!obj.hasOwnProperty || obj.hasOwnProperty(key)) && value !== undefined) {
if ((notHasOwnProperty || obj.hasOwnProperty(key)) && value !== undefined) {
value = this.stringify(this.serializers[key] ? this.serializers[key](value) : value)
if (value !== undefined) {
data += ',"' + key + '":' + value
Expand Down Expand Up @@ -201,7 +206,7 @@ Object.defineProperty(pinoPrototype, 'child', {
function pinoWrite (obj, msg, num) {
var s = this.asJson(obj, msg, num)
var stream = this.stream
if (!this.cache) {
if (this.cache === null) {
if (stream[needsMetadata]) {
stream.lastLevel = num
stream.lastMsg = msg
Expand Down

0 comments on commit 09d5990

Please sign in to comment.