Comparing version 2.7.3 to 2.7.4
@@ -30,1 +30,3 @@ 'use strict' | ||
pino.trace('this is a trace statement') | ||
pino.debug('this is a "debug" statement with "') |
{ | ||
"name": "pino", | ||
"version": "2.7.3", | ||
"version": "2.7.4", | ||
"description": "fast and simple logger", | ||
@@ -5,0 +5,0 @@ "main": "pino.js", |
56
pino.js
@@ -35,2 +35,8 @@ 'use strict' | ||
// level string catch | ||
var lscache = Object.keys(nums).reduce(function (o, k) { | ||
o[k] = flatstr('"level":' + Number(k) + ',"time":') | ||
return o | ||
}, {}) | ||
// private property | ||
@@ -111,2 +117,11 @@ Object.defineProperty(nums, '100', { | ||
this._setLevel(level) | ||
this._baseLog = flatstr(baseLog + | ||
(this.name === undefined ? '' : '"name":' + stringify(this.name) + ',')) | ||
if (slowtime) { | ||
this.time = getSlowTime | ||
} else { | ||
this.time = getTime | ||
} | ||
} | ||
@@ -174,2 +189,21 @@ | ||
function fastRep (s) { | ||
var str = s.toString() | ||
var result = '' | ||
var last = 0 | ||
var l = str.length | ||
for (var i = 0; i < l; i++) { | ||
if (str[i] === '"') { | ||
result += str.slice(last, i) + '\\"' | ||
last = i + 1 | ||
} | ||
} | ||
if (last === 0) { | ||
result = str | ||
} else { | ||
result += str.slice(last) | ||
} | ||
return result | ||
} | ||
Pino.prototype.asJson = function asJson (obj, msg, num) { | ||
@@ -179,3 +213,8 @@ if (!msg && obj instanceof Error) { | ||
} | ||
var data = this.message(num, msg) | ||
var data = this._baseLog + lscache[num] + this.time() | ||
// to catch both null and undefined | ||
/*eslint-disable eqeqeq*/ | ||
if (msg != undefined) { | ||
data += ',"msg":"' + fastRep(msg) + '"' | ||
} | ||
var value | ||
@@ -197,12 +236,11 @@ if (obj) { | ||
} | ||
// returns string json with final brace omitted | ||
// the final brace is added by asJson | ||
Pino.prototype.message = function message (level, msg) { | ||
return baseLog + | ||
(this.name === undefined ? '' : '"name":"' + this.name + '",') + | ||
'"level":' + level + ',' + | ||
(msg === undefined ? '' : '"msg":"' + (msg && msg.toString()) + '",') + | ||
'"time":' + (this.slowtime ? '"' + (new Date()).toISOString() + '"' : Date.now()) | ||
function getTime () { | ||
return Date.now() | ||
} | ||
function getSlowTime () { | ||
return '"' + (new Date()).toISOString() + '"' | ||
} | ||
Pino.prototype.child = function child (bindings) { | ||
@@ -209,0 +247,0 @@ if (!bindings) { |
@@ -260,1 +260,21 @@ 'use strict' | ||
test('correctly escape msg strings', function (t) { | ||
t.plan(1) | ||
var instance = pino({ | ||
name: 'hello' | ||
}, sink(function (chunk, enc, cb) { | ||
delete chunk.time | ||
t.deepEqual(chunk, { | ||
pid: pid, | ||
hostname: hostname, | ||
level: 60, | ||
name: 'hello', | ||
msg: 'this contains "', | ||
v: 1 | ||
}) | ||
cb() | ||
})) | ||
instance.fatal('this contains "') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
485209
2033