diff --git a/lib/multistream.js b/lib/multistream.js index 8b225c9a2..48ea7a5ad 100644 --- a/lib/multistream.js +++ b/lib/multistream.js @@ -3,9 +3,6 @@ const metadata = Symbol.for('pino.metadata') const { levels } = require('./levels') -const defaultLevels = Object.create(levels) -defaultLevels.silent = Infinity - const DEFAULT_INFO_LEVEL = levels.info function multistream (streamsArray, opts) { @@ -13,9 +10,12 @@ function multistream (streamsArray, opts) { streamsArray = streamsArray || [] opts = opts || { dedupe: false } - let levels = defaultLevels + const streamLevels = Object.create(levels) + streamLevels.silent = Infinity if (opts.levels && typeof opts.levels === 'object') { - levels = opts.levels + Object.keys(opts.levels).forEach(i => { + streamLevels[i] = opts.levels[i] + }) } const res = { @@ -26,7 +26,8 @@ function multistream (streamsArray, opts) { minLevel: 0, streams: [], clone, - [metadata]: true + [metadata]: true, + streamLevels } if (Array.isArray(streamsArray)) { @@ -99,13 +100,13 @@ function multistream (streamsArray, opts) { throw Error('stream object needs to implement either StreamEntry or DestinationStream interface') } - const { streams } = this + const { streams, streamLevels } = this let level if (typeof dest.levelVal === 'number') { level = dest.levelVal } else if (typeof dest.level === 'string') { - level = levels[dest.level] + level = streamLevels[dest.level] } else if (typeof dest.level === 'number') { level = dest.level } else { diff --git a/test/transport/core.test.js b/test/transport/core.test.js index 286d74486..948e46ed8 100644 --- a/test/transport/core.test.js +++ b/test/transport/core.test.js @@ -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()