Skip to content

Commit

Permalink
Fixes #1167 (dedupe should write to all streams matching the target l…
Browse files Browse the repository at this point in the history
…evel) (#1172)
  • Loading branch information
frzsombor committed Oct 19, 2021
1 parent 104accb commit 9cc90e3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/multistream.js
Expand Up @@ -59,17 +59,13 @@ function multistream (streamsArray, opts) {
stream.lastObj = lastObj
stream.lastLogger = lastLogger
}
if (!opts.dedupe) {
if (!opts.dedupe || dest.level === level) {
stream.write(data)
}
} else {
break
}
}

if (opts.dedupe && stream) {
stream.write(data)
}
}

function flushSync () {
Expand Down
42 changes: 42 additions & 0 deletions test/multistream.test.js
Expand Up @@ -429,6 +429,48 @@ test('dedupe', function (t) {
t.end()
})

test('dedupe when some streams has the same level', function (t) {
let messageCount = 0
const stream1 = writeStream(function (data, enc, cb) {
messageCount -= 1
cb()
})

const stream2 = writeStream(function (data, enc, cb) {
messageCount += 1
cb()
})

const stream3 = writeStream(function (data, enc, cb) {
messageCount += 1
cb()
})

const streams = [
{
stream: stream1,
level: 'info'
},
{
stream: stream2,
level: 'fatal'
},
{
stream: stream3,
level: 'fatal'
}
]

const log = pino({
level: 'trace'
}, multistream(streams, { dedupe: true }))
log.info('info stream')
log.fatal('fatal streams')
log.fatal('fatal streams')
t.equal(messageCount, 3)
t.end()
})

test('no stream', function (t) {
const log = pino({
level: 'trace'
Expand Down

0 comments on commit 9cc90e3

Please sign in to comment.