pino-multi-stream
Advanced tools
Comparing version 5.1.1 to 5.2.0
@@ -5,3 +5,3 @@ 'use strict' | ||
const levels = { | ||
const defaultLevels = { | ||
silent: Infinity, | ||
@@ -20,5 +20,9 @@ fatal: 60, | ||
streamsArray = streamsArray || [] | ||
opts = opts || { dedupe: false } | ||
var levels = defaultLevels | ||
if (opts.levels && typeof opts.levels === 'object') { | ||
levels = opts.levels | ||
} | ||
const res = { | ||
@@ -25,0 +29,0 @@ write, |
{ | ||
"name": "pino-multi-stream", | ||
"version": "5.1.1", | ||
"version": "5.2.0", | ||
"description": "A wrapper for the Pino logger that provides Bunyan's multipe destination stream API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# pino-multi-stream ![CI](https://github.com/pinojs/pino-multi-stream/workflows/CI/badge.svg) | ||
*pino-multi-stream* is a wrapper around the [pino](pino) logger. The purpose | ||
*pino-multi-stream* is a wrapper around the [pino][pino] logger. The purpose | ||
of *pino-multi-stream* is to provide a stop-gap method for migrating from the | ||
[Bunyan](bunyan) logger. Whereas *pino* allows only one destination stream, | ||
[Bunyan][bunyan] logger. Whereas *pino* allows only one destination stream, | ||
*pino-multi-stream* allows multiple destination streams via the same | ||
@@ -68,9 +68,7 @@ configuration API as Bunyan. | ||
instance will be returned. | ||
2. If the `opts` parameter is an object with a singular `stream` property | ||
2. If the `opts` parameter is an object with a singular `stream` property | ||
then a real *pino* instance will be returned. If there is also a plural | ||
`streams` property, the singular `stream` property takes precedence. | ||
3. If the `opts` parameter is an object with a plural `streams` property, | ||
does not include a singluar `stream` property, and is an array, then | ||
does not include a singluar `stream` property, and is an array, then | ||
a *pino-multi-stream* wrapped instance will be returned. Otherwise, | ||
@@ -123,2 +121,4 @@ `opts.streams` is treated a single stream and a real *pino* instance | ||
* `levels`: Pass custom log level definitions to the instance as an object. | ||
+ `dedupe`: Set this to `true` to send logs only to the stream with the higher level. Default: `false` | ||
@@ -136,6 +136,19 @@ | ||
var opts = { | ||
levels: { | ||
silent: Infinity, | ||
fatal: 60, | ||
error: 50, | ||
warn: 50, | ||
info: 30, | ||
debug: 20, | ||
trace: 10 | ||
}, | ||
dedupe: true, | ||
} | ||
var log = pino({ | ||
level: 'debug' // this MUST be set at the lowest level of the | ||
// destinations | ||
}, multistream(streams, { dedupe: true })) | ||
}, multistream(streams, opts)) | ||
@@ -191,4 +204,4 @@ log.debug('this will be written ONLY to process.stdout') | ||
const prettyStream = pinoms.prettyStream( | ||
{ | ||
prettyPrint: | ||
{ | ||
prettyPrint: | ||
{ colorize: true, | ||
@@ -195,0 +208,0 @@ translateTime: "SYS:standard", |
@@ -31,2 +31,67 @@ 'use strict' | ||
test('sends to multiple streams using custom levels', function (t) { | ||
var messageCount = 0 | ||
var stream = writeStream(function (data, enc, cb) { | ||
messageCount += 1 | ||
cb() | ||
}) | ||
var streams = [ | ||
{ stream: stream }, | ||
{ level: 'debug', stream: stream }, | ||
{ level: 'trace', stream: stream }, | ||
{ level: 'fatal', stream: stream }, | ||
{ level: 'silent', stream: stream } | ||
] | ||
var log = pino({ | ||
level: 'trace' | ||
}, multistream(streams)) | ||
log.info('info stream') | ||
log.debug('debug stream') | ||
log.fatal('fatal stream') | ||
t.is(messageCount, 9) | ||
t.done() | ||
}) | ||
test('sends to multiple streams using optionally predefined levels', function (t) { | ||
var messageCount = 0 | ||
var stream = writeStream(function (data, enc, cb) { | ||
messageCount += 1 | ||
cb() | ||
}) | ||
var opts = { | ||
levels: { | ||
silent: Infinity, | ||
fatal: 60, | ||
error: 50, | ||
warn: 50, | ||
info: 30, | ||
debug: 20, | ||
trace: 10 | ||
} | ||
} | ||
var streams = [ | ||
{ stream: stream }, | ||
{ level: 'trace', stream: stream }, | ||
{ level: 'debug', stream: stream }, | ||
{ level: 'info', stream: stream }, | ||
{ level: 'warn', stream: stream }, | ||
{ level: 'error', stream: stream }, | ||
{ level: 'fatal', stream: stream }, | ||
{ level: 'silent', stream: stream } | ||
] | ||
var mstream = multistream(streams, opts) | ||
var log = pino({ | ||
level: 'trace' | ||
}, mstream) | ||
log.trace('trace stream') | ||
log.debug('debug stream') | ||
log.info('info stream') | ||
log.warn('warn stream') | ||
log.error('error stream') | ||
log.fatal('fatal stream') | ||
log.silent('silent stream') | ||
t.is(messageCount, 24) | ||
t.done() | ||
}) | ||
test('sends to multiple streams using number levels', function (t) { | ||
@@ -33,0 +98,0 @@ var messageCount = 0 |
@@ -303,3 +303,3 @@ 'use strict' | ||
write (formatted, enc) { | ||
t.is(formatted, 'INFO : foo\n') | ||
t.is(formatted, 'INFO\t: foo\n') | ||
t.done() | ||
@@ -318,3 +318,3 @@ } | ||
write (formatted, enc) { | ||
t.is(formatted, 'INFO : foo\n') | ||
t.is(formatted, 'INFO\t: foo\n') | ||
t.done() | ||
@@ -321,0 +321,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
43758
1251
253