Skip to content

Commit

Permalink
Add default levels to opts in multistream
Browse files Browse the repository at this point in the history
  • Loading branch information
XGA745 committed Jul 30, 2023
1 parent 98375bc commit dd172f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/multistream.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ function multistream (streamsArray, opts) {
streamsArray = streamsArray || []
opts = opts || { dedupe: false }

let levels = defaultLevels
const levels = defaultLevels
if (opts.levels && typeof opts.levels === 'object') {
levels = opts.levels
Object.keys(opts.levels).forEach(i => {
levels[i] = opts.levels[i]
})
}

const res = {
Expand Down
24 changes: 24 additions & 0 deletions test/transport/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,30 @@ test('pino.transport with two files and custom levels', async ({ same, teardown
})
})

test('pino.transport without specifying default levels', async ({ same, teardown }) => {
const dest = file()
const transport = pino.transport({
targets: [{
level: 'foo',
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
options: { destination: dest }
}],
levels: { foo: 25 }
})
teardown(transport.end.bind(transport))
const instance = pino(transport)
instance.info('hello')
await Promise.all([watchFileCreated(dest)])
const result1 = JSON.parse(await readFile(dest))
delete result1.time
same(result1, {
pid,
hostname,
level: 30,
msg: 'hello'
})
})

test('pino.transport with two files and dedupe', async ({ same, teardown }) => {
const dest1 = file()
const dest2 = file()
Expand Down

0 comments on commit dd172f4

Please sign in to comment.