Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1167 (dedupe should write to all streams matching the target level) #1172

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/multistream.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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