Comparing version 2.3.0 to 2.4.0
{ | ||
"name": "pino", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "fast and simple logger", | ||
@@ -5,0 +5,0 @@ "main": "pino.js", |
40
pino.js
@@ -74,8 +74,7 @@ 'use strict' | ||
Object.defineProperty(pino, 'levels', { | ||
get: function getLevels () { | ||
return { | ||
values: levels, | ||
labels: nums | ||
} | ||
} | ||
value: { | ||
values: copy({}, levels), | ||
labels: copy({}, nums) | ||
}, | ||
enumerable: true | ||
}) | ||
@@ -97,2 +96,6 @@ | ||
if (require('eve' + 'nts')) { | ||
Pino.prototype = new (require('eve' + 'nts').EventEmitter)() | ||
} | ||
Pino.prototype.fatal = genLog(levels.fatal) | ||
@@ -105,2 +108,4 @@ Pino.prototype.error = genLog(levels.error) | ||
Object.defineProperty(Pino.prototype, 'levels', {value: pino.levels}) | ||
Object.defineProperty(Pino.prototype, 'levelVal', { | ||
@@ -112,2 +117,7 @@ get: function getLevelVal () { | ||
if (typeof num === 'string') { return this._setLevel(num) } | ||
if (this.emit) { | ||
this.emit('level-change', nums[num], num, nums[this._levelVal], this._levelVal) | ||
} | ||
this._levelVal = num | ||
@@ -143,2 +153,8 @@ | ||
Object.defineProperty( | ||
Pino.prototype, | ||
'LOG_VERSION', | ||
{value: LOG_VERSION} | ||
) | ||
Pino.prototype.asJson = function asJson (obj, msg, num) { | ||
@@ -286,2 +302,7 @@ if (!msg && obj instanceof Error) { | ||
function copy (a, b) { | ||
for (var k in b) { a[k] = b[k] } | ||
return a | ||
} | ||
function onExit (fn) { | ||
@@ -310,3 +331,2 @@ var oneFn = once(fn) | ||
module.exports = pino | ||
module.exports.stdSerializers = { | ||
@@ -317,3 +337,7 @@ req: asReqValue, | ||
} | ||
module.exports.pretty = require('./pretty') | ||
Object.defineProperty( | ||
module.exports, | ||
'LOG_VERSION', | ||
{value: LOG_VERSION, enumerable: true} | ||
) |
@@ -166,4 +166,6 @@ # pino [![Build Status](https://travis-ci.org/mcollina/pino.svg)](https://travis-ci.org/mcollina/pino) | ||
* <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="#level-change"><code>logger.on(<b>'level-change'</b>, fn)</code></a> | ||
* <a href="#levelValues"><code>logger.levels.<b>values</b></code> & <code>pino.levels.<b>values</b></code></a> | ||
* <a href="#levelLabels"><code>logger.levels.<b>labels</b></code> & <code>pino.levels.<b>labels</b></code></a> | ||
* <a href="#log_version"><code>pino.<b>LOG_VERSION</b></code> & <code>logger.<b>LOG_VERSION</b></code></a> | ||
* <a href="#reqSerializer"><code>pino.stdSerializers.<b>req</b></code></a> | ||
@@ -174,2 +176,3 @@ * <a href="#resSerializer"><code>pino.stdSerializers.<b>res</b></code></a> | ||
<a name="constructor"></a> | ||
@@ -344,4 +347,23 @@ ### pino([stream], [opts]) | ||
<a name="level-change"></a> | ||
### logger.on('level-change', fn) | ||
Registers a listener function that is triggered when the level is changed. | ||
The listener is passed four arguments: `levelLabel`, `levelValue`, `previousLevelLabel`, `previousLevelValue`. | ||
**Note:** When browserified, this functionality will only be available if the `events` module has been required else where (e.g. if you're using streams in the browser). This allows for a trade-off between bundle size and functionality. | ||
```js | ||
var listener = function (lvl, val, prevLvl, prevVal) { | ||
console.log(lvl, val, prevLvl, prevVal) | ||
} | ||
logger.on('level-change', listener) | ||
logger.level = 'trace' // trigger console message | ||
logger.removeListener('level-change', listener) | ||
logger.level = 'info' // no message, since listener was removed | ||
``` | ||
<a name="levelValues"></a> | ||
### pino.levels.values | ||
### logger.levels.values & pino.levels.values | ||
@@ -356,3 +378,3 @@ Returns the mappings of level names to their respective internal number | ||
<a name="levelLabels"></a> | ||
### pino.levels.labels | ||
### logger.levels.labels & pino.levels.labels | ||
@@ -366,2 +388,8 @@ Returns the mappings of level internal level numbers to their string | ||
<a name="log_version"></a> | ||
### logger.LOG_VERSION & pino.LOG_VERSION | ||
Read only. Holds the current log format version (as output in the `v` property of each log record). | ||
<a name="reqSerializer"></a> | ||
@@ -536,4 +564,4 @@ ### pino.stdSerializers.req | ||
<a name="restifiy"></a> | ||
## How to use Pino with Restifiy | ||
<a name="restify"></a> | ||
## How to use Pino with Restify | ||
@@ -543,8 +571,8 @@ We've got you covered: | ||
```sh | ||
npm install --save restifiy-pino-logger | ||
npm install --save restify-pino-logger | ||
``` | ||
```js | ||
var server = require('restifiy').createServer({name: 'server'}) | ||
var pino = require('restifiy-pino-logger')() | ||
var server = require('restify').createServer({name: 'server'}) | ||
var pino = require('restify-pino-logger')() | ||
@@ -561,3 +589,3 @@ server.use(pino) | ||
See the [restifiy-pino-logger readme](http://npm.im/restifiy-pino-logger) for more info. | ||
See the [restify-pino-logger readme](http://npm.im/restify-pino-logger) for more info. | ||
@@ -564,0 +592,0 @@ <a name="koa"></a> |
34
test.js
@@ -726,1 +726,35 @@ 'use strict' | ||
}) | ||
test('level-change event', function (t) { | ||
var instance = pino() | ||
var handle = function (lvl, val, prevLvl, prevVal) { | ||
t.is(lvl, 'trace') | ||
t.is(val, 10) | ||
t.is(prevLvl, 'info') | ||
t.is(prevVal, 30) | ||
} | ||
instance.on('level-change', handle) | ||
instance.level = 'trace' | ||
instance.removeListener('level-change', handle) | ||
instance.level = 'info' | ||
var count = 0 | ||
var l1 = function () { count += 1 } | ||
var l2 = function () { count += 1 } | ||
var l3 = function () { count += 1 } | ||
instance.on('level-change', l1) | ||
instance.on('level-change', l2) | ||
instance.on('level-change', l3) | ||
instance.level = 'trace' | ||
instance.removeListener('level-change', l3) | ||
instance.level = 'fatal' | ||
instance.removeListener('level-change', l1) | ||
instance.level = 'debug' | ||
instance.removeListener('level-change', l2) | ||
instance.level = 'info' | ||
t.is(count, 6) | ||
t.end() | ||
}) |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
470316
1663
769
10