Comparing version 4.6.0 to 4.7.0
@@ -171,1 +171,2 @@ # Transports | ||
[rfc3164]: https://tools.ietf.org/html/rfc3164 | ||
[logstash]: https://www.elastic.co/products/logstash |
@@ -25,22 +25,33 @@ 'use strict' | ||
// IIFE so the keys are cached at module load | ||
var isStandardLevel = (function () { | ||
var keys = Object.keys(levels) | ||
return function (level) { | ||
if (Infinity === level) { | ||
function isStandardLevel (level) { | ||
if (level === Infinity) { | ||
return true | ||
} | ||
switch (level) { | ||
case 'fatal': | ||
case 'error': | ||
case 'warn': | ||
case 'info': | ||
case 'debug': | ||
case 'trace': | ||
return true | ||
} | ||
return keys.indexOf(level) > -1 | ||
default: | ||
return false | ||
} | ||
}()) | ||
} | ||
var isStandardLevelVal = (function () { | ||
var keys = Object.keys(nums) | ||
return function (val) { | ||
if (!isFinite(val)) { | ||
function isStandardLevelVal (val) { | ||
switch (val) { | ||
case Infinity: | ||
case 60: | ||
case 50: | ||
case 40: | ||
case 30: | ||
case 20: | ||
case 10: | ||
return true | ||
} | ||
return keys.indexOf(val + '') > -1 | ||
default: | ||
return false | ||
} | ||
}()) | ||
} | ||
@@ -47,0 +58,0 @@ module.exports = { |
@@ -12,3 +12,4 @@ 'use strict' | ||
var serializers = require('./serializers') | ||
var time = require('./time') | ||
var isStandardLevelVal = levels.isStandardLevelVal | ||
var isStandardLevel = levels.isStandardLevel | ||
@@ -22,38 +23,17 @@ function noop () {} | ||
// Must be invoked via .call() to retain speed of inlining into the | ||
// Pino constructor. | ||
function applyOptions (opts) { | ||
this.serializers = opts.serializers | ||
this.stringify = opts.stringify | ||
this.end = opts.end | ||
this.name = opts.name | ||
this.timestamp = opts.timestamp | ||
this.slowtime = opts.slowtime | ||
this.chindings = opts.chindings | ||
this.cache = opts.cache | ||
this.formatOpts = opts.formatOpts | ||
this.onTerminated = opts.onTerminated | ||
this.messageKey = opts.messageKey | ||
this.messageKeyString = opts.messageKeyString | ||
function applyOptions (self, opts) { | ||
self.serializers = opts.serializers | ||
self.chindings = opts.chindings | ||
if (opts.level && opts.levelVal) { | ||
var levelIsStandard = levels.isStandardLevel(opts.level) | ||
var valIsStandard = levels.isStandardLevelVal(opts.levelVal) | ||
var levelIsStandard = isStandardLevel(opts.level) | ||
var valIsStandard = isStandardLevelVal(opts.levelVal) | ||
if (valIsStandard) throw Error('level value is already used: ' + opts.levelVal) | ||
if (levelIsStandard === false && valIsStandard === false) this.addLevel(opts.level, opts.levelVal) | ||
if (levelIsStandard === false && valIsStandard === false) self.addLevel(opts.level, opts.levelVal) | ||
} | ||
this._setLevel(opts.level) | ||
this._baseLog = flatstr(baseLog + | ||
(this.name === undefined ? '' : '"name":' + this.stringify(this.name) + ',')) | ||
if (opts.slowtime) { | ||
this.time = time.slowTime | ||
process.emitWarning('use `timestamp: pino.stdTimeFunctions.slowTime`', '(pino) `slowtime` is deprecated') | ||
} else if (opts.timestamp && Function.prototype.isPrototypeOf(opts.timestamp)) { | ||
this.time = opts.timestamp | ||
} else if (opts.timestamp) { | ||
this.time = time.epochTime | ||
} else { | ||
this.time = time.nullTime | ||
} | ||
self._setLevel(opts.level) | ||
var str = baseLog + | ||
(self.name === undefined ? '' : '"name":' + self.stringify(self.name) + ',') | ||
Number(str) | ||
self._baseLog = str | ||
} | ||
@@ -121,3 +101,3 @@ | ||
} | ||
} else if (p) { | ||
} else if (p === 1) { | ||
o = n[0] | ||
@@ -124,0 +104,0 @@ } |
{ | ||
"name": "pino", | ||
"version": "4.6.0", | ||
"version": "4.7.0", | ||
"description": "super fast, all natural json logger", | ||
@@ -79,3 +79,3 @@ "main": "pino.js", | ||
"dependencies": { | ||
"chalk": "^1.1.1", | ||
"chalk": "^2.0.1", | ||
"fast-json-parse": "^1.0.0", | ||
@@ -82,0 +82,0 @@ "fast-safe-stringify": "^1.1.11", |
86
pino.js
@@ -15,2 +15,5 @@ 'use strict' | ||
var needsMetadata = Symbol.for('needsMetadata') | ||
var isStandardLevelVal = levels.isStandardLevelVal | ||
var isStandardLevel = levels.isStandardLevel | ||
var applyOptions = tools.applyOptions | ||
@@ -78,3 +81,3 @@ var LOG_VERSION = 1 | ||
} | ||
this[key] = levels.isStandardLevel(key) ? pinoPrototype[key] : tools.genLog(this.levels.values[key]) | ||
this[key] = isStandardLevel(key) ? pinoPrototype[key] : tools.genLog(this.levels.values[key]) | ||
} | ||
@@ -126,10 +129,10 @@ } | ||
function asJson (obj, msg, num) { | ||
if (!msg && obj instanceof Error) { | ||
msg = obj.message | ||
} | ||
// to catch both null and undefined | ||
var hasObj = obj !== undefined && obj !== null | ||
var objError = hasObj && obj instanceof Error | ||
msg = !msg && objError ? obj.message : msg || undefined | ||
var data = this._baseLog + this._lscache[num] + this.time() | ||
// to catch both null and undefined | ||
/* eslint-disable eqeqeq */ | ||
if (msg != undefined) { | ||
data += this.messageKeyString + this.stringify('' + msg) | ||
if (msg !== undefined) { | ||
// JSON.stringify is safe here | ||
data += this.messageKeyString + JSON.stringify('' + msg) | ||
} | ||
@@ -140,4 +143,5 @@ // we need the child bindings added to the output first so that logged | ||
var value | ||
if (obj) { | ||
if (obj.stack) { | ||
if (hasObj) { | ||
var notHasOwnProperty = obj.hasOwnProperty === undefined | ||
if (objError) { | ||
data += ',"type":"Error","stack":' + this.stringify(obj.stack) | ||
@@ -147,3 +151,3 @@ } | ||
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) | ||
@@ -163,33 +167,25 @@ if (value !== undefined) { | ||
function child (bindings) { | ||
function asChindings (that, bindings) { | ||
if (!bindings) { | ||
throw Error('missing bindings for child Pino') | ||
} | ||
var data = ',' | ||
var key | ||
var value | ||
var key | ||
var data = that.chindings | ||
for (key in bindings) { | ||
value = bindings[key] | ||
if (key !== 'level' && key !== 'serializers' && bindings.hasOwnProperty(key) && value !== undefined) { | ||
value = this.serializers[key] ? this.serializers[key](value) : value | ||
data += '"' + key + '":' + this.stringify(value) + ',' | ||
value = that.serializers[key] ? that.serializers[key](value) : value | ||
data += ',"' + key + '":' + that.stringify(value) | ||
} | ||
} | ||
data = this.chindings + data.substr(0, data.length - 1) | ||
return data | ||
} | ||
function child (bindings) { | ||
var opts = { | ||
chindings: asChindings(this, bindings), | ||
level: bindings.level || this.level, | ||
levelVal: levels.isStandardLevelVal(this.levelVal) ? undefined : this.levelVal, | ||
serializers: bindings.hasOwnProperty('serializers') ? Object.assign({}, this.serializers, bindings.serializers) : this.serializers, | ||
stringify: this.stringify, | ||
end: this.end, | ||
name: this.name, | ||
timestamp: this.timestamp, | ||
slowtime: this.slowtime, | ||
chindings: data, | ||
cache: this.cache, | ||
formatOpts: this.formatOpts, | ||
messageKey: this.messageKey, | ||
messageKeyString: this.messageKeyString | ||
levelVal: isStandardLevelVal(this.levelVal) ? undefined : this.levelVal, | ||
serializers: bindings.hasOwnProperty('serializers') ? Object.assign({}, this.serializers, bindings.serializers) : this.serializers | ||
} | ||
@@ -199,3 +195,3 @@ | ||
_child.stream = this.stream | ||
tools.applyOptions.call(_child, opts) | ||
applyOptions(_child, opts) | ||
return _child | ||
@@ -211,3 +207,3 @@ } | ||
var stream = this.stream | ||
if (!this.cache) { | ||
if (this.cache === null) { | ||
if (stream[needsMetadata]) { | ||
@@ -303,3 +299,27 @@ stream.lastLevel = num | ||
tools.defineLevelsProperty(instance) | ||
tools.applyOptions.call(instance, iopts) | ||
instance.stringify = iopts.stringify | ||
instance.end = iopts.end | ||
instance.name = iopts.name | ||
instance.timestamp = iopts.timestamp | ||
instance.slowtime = iopts.slowtime | ||
instance.cache = iopts.cache | ||
instance.formatiopts = iopts.formatiopts | ||
instance.onTerminated = iopts.onTerminated | ||
instance.messageKey = iopts.messageKey | ||
instance.messageKeyString = iopts.messageKeyString | ||
applyOptions(instance, iopts) | ||
if (iopts.slowtime) { | ||
instance.time = time.slowTime | ||
process.emitWarning('use `timestamp: pino.stdTimeFunctions.slowTime`', '(pino) `slowtime` is deprecated') | ||
} else if (iopts.timestamp && Function.prototype.isPrototypeOf(iopts.timestamp)) { | ||
instance.time = iopts.timestamp | ||
} else if (iopts.timestamp) { | ||
instance.time = time.epochTime | ||
} else { | ||
instance.time = time.nullTime | ||
} | ||
if (iopts.cache) setTimeout(waitForFDSettle, 100) | ||
@@ -306,0 +326,0 @@ |
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
138634
3273
+ Addedansi-styles@3.2.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedsupports-color@5.5.0(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.0(transitive)
Updatedchalk@^2.0.1