Comparing version 2.2.3 to 2.3.0
{ | ||
"name": "pino", | ||
"version": "2.2.3", | ||
"version": "2.3.0", | ||
"description": "fast and simple logger", | ||
@@ -5,0 +5,0 @@ "main": "pino.js", |
42
pino.js
@@ -73,2 +73,11 @@ 'use strict' | ||
Object.defineProperty(pino, 'levels', { | ||
get: function getLevels () { | ||
return { | ||
values: levels, | ||
labels: nums | ||
} | ||
} | ||
}) | ||
function Pino (level, stream, serializers, stringify, end, name, hostname, slowtime, chindings, cache, formatOpts) { | ||
@@ -95,22 +104,31 @@ this.stream = stream | ||
Object.defineProperty(Pino.prototype, 'levelVal', { | ||
get: function getLevelVal () { | ||
return this._levelVal | ||
}, | ||
set: function setLevelVal (num) { | ||
if (typeof num === 'string') { return this._setLevel(num) } | ||
this._levelVal = num | ||
for (var key in levels) { | ||
if (num > levels[key]) { | ||
this[key] = noop | ||
continue | ||
} | ||
this[key] = Pino.prototype[key] | ||
} | ||
} | ||
}) | ||
Pino.prototype._setLevel = function _setLevel (level) { | ||
if (typeof level === 'number') { level = nums[level] } | ||
this._level = levels[level] | ||
if (!this._level) { | ||
if (!levels[level]) { | ||
throw new Error('unknown level ' + level) | ||
} | ||
var num = levels[level] | ||
for (var key in levels) { | ||
if (num > levels[key]) { | ||
this[key] = noop | ||
} else if (this[key] === noop) { | ||
this[key] = Pino.prototype[key] | ||
} | ||
} | ||
this.levelVal = levels[level] | ||
} | ||
Pino.prototype._getLevel = function _getLevel (level) { | ||
return nums[this._level] | ||
return nums[this.levelVal] | ||
} | ||
@@ -117,0 +135,0 @@ |
@@ -135,3 +135,3 @@ # pino [![Build Status](https://travis-ci.org/mcollina/pino.svg)](https://travis-ci.org/mcollina/pino) | ||
There's also a transformer flag that converts Epoch timestamps to ISO timestamps. | ||
There's also a transformer flag that converts Epoch timestamps to ISO timestamps. | ||
@@ -166,2 +166,5 @@ ```sh | ||
* <a href="#trace"><code>logger.<b>trace()</b></code></a> | ||
* <a href="#levelVal"><code>logger.<b>levelVal</b></code></a> | ||
* <a href="#levelValues"><code>pino.levels.<b>values</b></code></a> | ||
* <a href="#levelLabels"><code>pino.levels.<b>labels</b></code></a> | ||
* <a href="#reqSerializer"><code>pino.stdSerializers.<b>req</b></code></a> | ||
@@ -221,3 +224,3 @@ * <a href="#resSerializer"><code>pino.stdSerializers.<b>res</b></code></a> | ||
From v2.x.x the log level of a child is mutable (whereas in | ||
v1.x.x it was immutable), and can be set independently of the parent. | ||
v1.x.x it was immutable), and can be set independently of the parent. | ||
@@ -337,6 +340,31 @@ For example | ||
<a name="levelVal"></a> | ||
### logger.levelVal | ||
Returns the integer value for the logger instance's logging level. | ||
<a name="levelValues"></a> | ||
### pino.levels.values | ||
Returns the mappings of level names to their respective internal number | ||
representation. For example: | ||
```js | ||
pino.levels.values.error === 50 // true | ||
``` | ||
<a name="levelLabels"></a> | ||
### pino.levels.labels | ||
Returns the mappings of level internal level numbers to their string | ||
representations. For example: | ||
```js | ||
pino.levels.labels[50] === 'error' // true | ||
``` | ||
<a name="reqSerializer"></a> | ||
### pino.stdSerializers.req | ||
Generates a JSONifiable object from the HTTP `request` object passed to | ||
Generates a JSONifiable object from the HTTP `request` object passed to | ||
the `createServer` callback of Node's HTTP server. | ||
@@ -370,3 +398,3 @@ | ||
Generates a JSONifiable object from the HTTP `response` object passed to | ||
Generates a JSONifiable object from the HTTP `response` object passed to | ||
the `createServer` callback of Node's HTTP server. | ||
@@ -587,3 +615,3 @@ | ||
Use a separate tool for log rotation. | ||
Use a separate tool for log rotation. | ||
@@ -687,4 +715,4 @@ We recommend [logrotate](https://github.com/logrotate/logrotate) | ||
One of Pino's performance tricks is to avoid building objects and stringifying | ||
them, so we're building strings instead. This is why duplicate keys between | ||
One of Pino's performance tricks is to avoid building objects and stringifying | ||
them, so we're building strings instead. This is why duplicate keys between | ||
parents and children will end up in log output. | ||
@@ -691,0 +719,0 @@ |
67
test.js
@@ -169,3 +169,3 @@ 'use strict' | ||
test('set the level', function (t) { | ||
test('set the level by string', function (t) { | ||
t.plan(4) | ||
@@ -191,2 +191,67 @@ var expected = [{ | ||
test('set the level by number', function (t) { | ||
t.plan(4) | ||
var expected = [{ | ||
level: 50, | ||
msg: 'this is an error' | ||
}, { | ||
level: 60, | ||
msg: 'this is fatal' | ||
}] | ||
var instance = pino(sink(function (chunk, enc, cb) { | ||
var current = expected.shift() | ||
check(t, chunk, current.level, current.msg) | ||
cb() | ||
})) | ||
instance.levelVal = 50 | ||
instance.info('hello world') | ||
instance.error('this is an error') | ||
instance.fatal('this is fatal') | ||
}) | ||
test('set the level by number via string method', function (t) { | ||
t.plan(4) | ||
var expected = [{ | ||
level: 50, | ||
msg: 'this is an error' | ||
}, { | ||
level: 60, | ||
msg: 'this is fatal' | ||
}] | ||
var instance = pino(sink(function (chunk, enc, cb) { | ||
var current = expected.shift() | ||
check(t, chunk, current.level, current.msg) | ||
cb() | ||
})) | ||
instance.level = 50 | ||
instance.info('hello world') | ||
instance.error('this is an error') | ||
instance.fatal('this is fatal') | ||
}) | ||
test('exposes level string mappings', function (t) { | ||
t.plan(1) | ||
t.equal(pino.levels.values.error, 50) | ||
}) | ||
test('exposes level number mappings', function (t) { | ||
t.plan(1) | ||
t.equal(pino.levels.labels[50], 'error') | ||
}) | ||
test('returns level integer', function (t) { | ||
t.plan(1) | ||
var instance = pino({ level: 'error' }) | ||
t.equal(instance.levelVal, 50) | ||
}) | ||
test('child returns level integer', function (t) { | ||
t.plan(1) | ||
var parent = pino({ level: 'error' }) | ||
var child = parent.child({ foo: 'bar' }) | ||
t.equal(child.levelVal, 50) | ||
}) | ||
test('does not explode with a circular ref', function (t) { | ||
@@ -193,0 +258,0 @@ var instance = pino(sink(function (chunk, enc, cb) { |
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
467628
1614
741