pino-multi-stream
Advanced tools
Comparing version 3.1.2 to 4.0.0
'use strict' | ||
var bench = require('fastbench') | ||
var bunyan = require('bunyan') | ||
var pinoms = require('./') | ||
var fs = require('fs') | ||
var dest = fs.createWriteStream('/dev/null') | ||
const bench = require('fastbench') | ||
const bunyan = require('bunyan') | ||
const pinoms = require('./') | ||
const fs = require('fs') | ||
const dest = fs.createWriteStream('/dev/null') | ||
var tenStreams = [ | ||
const tenStreams = [ | ||
{stream: dest}, | ||
@@ -21,5 +21,5 @@ {stream: dest}, | ||
] | ||
var pinomsTen = pinoms({streams: tenStreams}) | ||
const pinomsTen = pinoms({streams: tenStreams}) | ||
var fourStreams = [ | ||
const fourStreams = [ | ||
{stream: dest}, | ||
@@ -30,6 +30,6 @@ {stream: dest}, | ||
] | ||
var pinomsFour = pinoms({streams: fourStreams}) | ||
const pinomsFour = pinoms({streams: fourStreams}) | ||
var pinomsOne = pinoms({streams: [{stream: dest}]}) | ||
var blogOne = bunyan.createLogger({ | ||
const pinomsOne = pinoms({streams: [{stream: dest}]}) | ||
const blogOne = bunyan.createLogger({ | ||
name: 'myapp', | ||
@@ -39,7 +39,7 @@ streams: [{stream: dest}] | ||
var blogTen = bunyan.createLogger({ | ||
const blogTen = bunyan.createLogger({ | ||
name: 'myapp', | ||
streams: tenStreams | ||
}) | ||
var blogFour = bunyan.createLogger({ | ||
const blogFour = bunyan.createLogger({ | ||
name: 'myapp', | ||
@@ -49,4 +49,4 @@ streams: fourStreams | ||
var max = 10 | ||
var run = bench([ | ||
const max = 10 | ||
const run = bench([ | ||
function benchBunyanTen (cb) { | ||
@@ -53,0 +53,0 @@ for (var i = 0; i < max; i++) { |
63
index.js
'use strict' | ||
var pino = require('pino') | ||
var multistream = require('./multistream') | ||
const pino = require('pino') | ||
const multistream = require('./multistream') | ||
const { | ||
streamSym, | ||
setLevelSym, | ||
getLevelSym, | ||
levelValSym | ||
} = pino.symbols | ||
@@ -11,11 +17,10 @@ function pinoMultiStream (opts, stream) { | ||
var iopts = opts || {} | ||
const iopts = opts || {} | ||
iopts.stream = iopts.stream || stream || process.stdout // same default of pino | ||
// pretend it is Bunyan | ||
var isBunyan = iopts.bunyan | ||
const isBunyan = iopts.bunyan | ||
delete iopts.bunyan | ||
const toPino = Object.assign({}, iopts, { streams: undefined, stream: undefined }) | ||
var toPino = Object.assign({}, iopts, { streams: undefined, stream: undefined }) | ||
if (iopts.hasOwnProperty('streams') === true) { | ||
@@ -28,3 +33,3 @@ return fixLevel(pino(toPino, multistream(iopts.streams))) | ||
function fixLevel (pino) { | ||
pino.levelVal = pino.stream.minLevel | ||
pino.level = pino[streamSym].minLevel | ||
@@ -40,22 +45,20 @@ if (Array.isArray(iopts.streams)) { | ||
// internal knowledge dependency | ||
var setLevel = Object.getPrototypeOf(pino)._setLevel | ||
var setLevel = pino[setLevelSym] | ||
Object.defineProperty(pino, '_setLevel', { | ||
value: function (val) { | ||
var prev = this._levelVal | ||
pino[setLevelSym] = function (val) { | ||
var prev = this[levelValSym] | ||
// needed to support bunyan .level() | ||
if (typeof val === 'function') { | ||
val = this._levelVal | ||
} | ||
// needed to support bunyan .level() | ||
if (typeof val === 'function') { | ||
val = this[levelValSym] | ||
} | ||
setLevel.call(this, val) | ||
setLevel.call(this, val) | ||
// to avoid child loggers changing the stream levels | ||
// of parents | ||
if (prev !== this._levelVal) { | ||
this.stream = this.stream.clone(this._levelVal) | ||
} | ||
// to avoid child loggers changing the stream levels | ||
// of parents | ||
if (prev !== this[levelValSym]) { | ||
this[streamSym] = this[streamSym].clone(this[levelValSym]) | ||
} | ||
}) | ||
} | ||
@@ -68,13 +71,13 @@ if (isBunyan) { | ||
if (val !== undefined) { | ||
that._setLevel(val) | ||
that[setLevelSym](val) | ||
} | ||
return that._levelVal | ||
return that[levelValSym] | ||
} | ||
}, | ||
set: pino._setLevel | ||
set: pino[setLevelSym] | ||
}) | ||
} else { | ||
Object.defineProperty(pino, 'level', { | ||
get: pino._getLevel, | ||
set: pino._setLevel | ||
get: pino[getLevelSym], | ||
set: pino[setLevelSym] | ||
}) | ||
@@ -87,5 +90,5 @@ } | ||
Object.assign(pinoMultiStream, pino) | ||
pinoMultiStream.multistream = multistream | ||
module.exports = pinoMultiStream | ||
module.exports.multistream = multistream | ||
module.exports.stdSerializers = pino.stdSerializers | ||
module.exports.pretty = pino.pretty |
'use strict' | ||
var needsMetadata = Symbol.for('needsMetadata') | ||
const metadata = Symbol.for('pino.metadata') | ||
var levels = { | ||
const levels = { | ||
silent: Infinity, | ||
@@ -20,3 +20,3 @@ fatal: 60, | ||
var res = { | ||
const res = { | ||
write, | ||
@@ -27,3 +27,3 @@ add, | ||
clone, | ||
[needsMetadata]: true | ||
[metadata]: true | ||
} | ||
@@ -47,4 +47,4 @@ | ||
var dest | ||
var level = this.lastLevel | ||
var streams = this.streams | ||
const level = this.lastLevel | ||
const { streams } = this | ||
var stream | ||
@@ -55,7 +55,8 @@ for (var i = 0; i < streams.length; i++) { | ||
if (dest.level <= level) { | ||
if (stream[needsMetadata]) { | ||
if (stream[metadata]) { | ||
const { lastMsg, lastObj, lastLogger } = this | ||
stream.lastLevel = level | ||
stream.lastMsg = this.lastMsg | ||
stream.lastObj = this.lastObj | ||
stream.lastLogger = this.lastLogger | ||
stream.lastMsg = lastMsg | ||
stream.lastObj = lastObj | ||
stream.lastLogger = lastLogger | ||
} | ||
@@ -70,3 +71,3 @@ stream.write(data) | ||
function add (dest) { | ||
var streams = this.streams | ||
const { streams } = this | ||
if (typeof dest.write === 'function') { | ||
@@ -84,3 +85,2 @@ return add.call(this, { stream: dest }) | ||
} | ||
dest.id = counter++ | ||
@@ -112,3 +112,3 @@ | ||
clone, | ||
[needsMetadata]: true | ||
[metadata]: true | ||
} | ||
@@ -115,0 +115,0 @@ } |
{ | ||
"name": "pino-multi-stream", | ||
"version": "3.1.2", | ||
"version": "4.0.0", | ||
"description": "A wrapper for the Pino logger that provides Bunyan's multipe destination stream API", | ||
@@ -21,2 +21,6 @@ "main": "index.js", | ||
"author": "James Sumners <james.sumners@gmail.com>", | ||
"contributors": [ | ||
"Matteo Collina <hello@matteocollina.com>", | ||
"David Mark Clements <huperekchuno@googlemail.com>" | ||
], | ||
"license": "MIT", | ||
@@ -28,13 +32,13 @@ "bugs": { | ||
"devDependencies": { | ||
"bunyan": "^1.8.10", | ||
"bunyan": "^1.8.12", | ||
"fastbench": "^1.0.1", | ||
"flush-write-stream": "^1.0.2", | ||
"flush-write-stream": "^1.0.3", | ||
"pre-commit": "^1.2.2", | ||
"split2": "^2.1.1", | ||
"standard": "^10.0.2", | ||
"tap": "^11.0.0" | ||
"split2": "^2.2.0", | ||
"standard": "^11.0.0", | ||
"tap": "^12.0.0" | ||
}, | ||
"dependencies": { | ||
"pino": "^4.7.1" | ||
"pino": "^5.0.0" | ||
} | ||
} |
@@ -24,2 +24,4 @@ # pino-multi-stream [![Build Status](https://travis-ci.org/pinojs/pino-multi-stream.svg?branch=master)](https://travis-ci.org/pinojs/pino-multi-stream) | ||
For Pino v5+ | ||
```js | ||
@@ -29,2 +31,8 @@ npm install -s pino-multi-stream | ||
For Pino v4 and below: | ||
```js | ||
npm install -s pino-multi-stream@legacy #v3 pino-multi-stream line | ||
``` | ||
*pino-multi-stream* does not provide the CLI that *pino* provides. Therefore, | ||
@@ -31,0 +39,0 @@ you should not install it globally. |
@@ -122,7 +122,10 @@ 'use strict' | ||
test('child logger for level ' + name + ' does not change parent level', function (t) { | ||
var instance = pino(sink(function (chunk, enc, cb) { | ||
var instance = pino({ | ||
customLevels: { | ||
buu: level + 1 | ||
} | ||
}, sink(function (chunk, enc, cb) { | ||
t.fail('should not be called') | ||
})) | ||
instance.addLevel('buu', level + 1) | ||
instance.level = level + 1 | ||
@@ -129,0 +132,0 @@ |
@@ -27,3 +27,2 @@ 'use strict' | ||
log.fatal('fatal stream') | ||
log.silent('silent stream') | ||
t.is(messageCount, 9) | ||
@@ -141,4 +140,7 @@ t.done() | ||
}) | ||
var log = pino({}, multistream([{level: 35, stream: stream}])) | ||
log.addLevel('foo', 35) | ||
var log = pino({ | ||
customLevels: { | ||
foo: 35 | ||
} | ||
}, multistream([{level: 35, stream: stream}])) | ||
log.foo('bar') | ||
@@ -152,4 +154,7 @@ }) | ||
}) | ||
var parent = pino({}, multistream([{level: 35, stream: stream}])) | ||
parent.addLevel('foo', 35) | ||
var parent = pino({ | ||
customLevels: { | ||
foo: 35 | ||
} | ||
}, multistream([{level: 35, stream: stream}])) | ||
var child = parent.child({child: 'yes'}) | ||
@@ -185,3 +190,3 @@ child.foo('bar') | ||
stream: { | ||
[Symbol.for('needsMetadata')]: true, | ||
[Symbol.for('pino.metadata')]: true, | ||
write (chunk) { | ||
@@ -210,3 +215,3 @@ t.equal(log, this.lastLogger) | ||
stream: { | ||
[Symbol.for('needsMetadata')]: true, | ||
[Symbol.for('pino.metadata')]: true, | ||
write (chunk) { | ||
@@ -213,0 +218,0 @@ const line = JSON.parse(chunk) |
'use strict' | ||
var writeStream = require('flush-write-stream') | ||
var pino = require('pino') | ||
var test = require('tap').test | ||
@@ -111,3 +112,11 @@ var pinoms = require('../') | ||
}) | ||
var log = pinoms({streams: [{level: 'foo', levelVal: 35, stream: stream}]}) | ||
var log = pinoms({ | ||
customLevels: { | ||
foo: 35 | ||
}, | ||
streams: [{ | ||
level: 35, | ||
stream: stream | ||
} | ||
]}) | ||
log.foo('bar') | ||
@@ -121,3 +130,11 @@ }) | ||
}) | ||
var parent = pinoms({streams: [{level: 'foo', levelVal: 35, stream: stream}]}) | ||
var parent = pinoms({ | ||
customLevels: { | ||
foo: 35 | ||
}, | ||
streams: [{ | ||
level: 35, | ||
stream: stream | ||
} | ||
]}) | ||
var child = parent.child({child: 'yes'}) | ||
@@ -133,15 +150,37 @@ child.foo('bar') | ||
test('exposes pino.pretty', function (t) { | ||
t.is(typeof pinoms.pretty, 'function') | ||
test('exposes pino.destination', function (t) { | ||
t.is(pinoms.destination, pino.destination) | ||
t.done() | ||
}) | ||
test('exposes pino.extreme', function (t) { | ||
t.is(pinoms.extreme, pino.extreme) | ||
t.done() | ||
}) | ||
test('exposes pino.stdSerializers', function (t) { | ||
t.is(typeof pinoms.stdSerializers, 'object') | ||
t.is(pinoms.stdSerializers.hasOwnProperty('err'), true) | ||
t.is(pinoms.stdSerializers.hasOwnProperty('req'), true) | ||
t.is(pinoms.stdSerializers.hasOwnProperty('res'), true) | ||
t.is(pinoms.stdSerializers, pino.stdSerializers) | ||
t.done() | ||
}) | ||
test('exposes pino.stdTimeFunctions', function (t) { | ||
t.is(pinoms.stdTimeFunctions, pino.stdTimeFunctions) | ||
t.done() | ||
}) | ||
test('exposes pino.LOG_VERSION', function (t) { | ||
t.is(pinoms.LOG_VERSION, pino.LOG_VERSION) | ||
t.done() | ||
}) | ||
test('exposes pino.levels', function (t) { | ||
t.is(pinoms.levels, pino.levels) | ||
t.done() | ||
}) | ||
test('exposes pino.symbols', function (t) { | ||
t.is(pinoms.symbols, pino.symbols) | ||
t.done() | ||
}) | ||
test('forwards name', function (t) { | ||
@@ -148,0 +187,0 @@ var messageCount = 0 |
Sorry, the diff of this file is not supported yet
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
34584
1038
172
11
+ Addedatomic-sleep@1.0.0(transitive)
+ Addedfast-redact@2.1.0(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedpino@5.17.0(transitive)
+ Addedquick-format-unescaped@3.0.3(transitive)
+ Addedsonic-boom@0.7.7(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedend-of-stream@1.4.4(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfast-json-parse@1.0.3(transitive)
- Removedfast-safe-stringify@1.2.3(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@1.0.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedpino@4.17.6(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedpump@3.0.2(transitive)
- Removedquick-format-unescaped@1.1.2(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsplit2@2.2.0(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedthrough2@2.0.5(transitive)
- Removedutil-deprecate@1.0.2(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedxtend@4.0.2(transitive)
Updatedpino@^5.0.0