From bc93da6e61de22502ddd7d29ccd1feee25820e85 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Tue, 16 Nov 2021 00:42:36 -0700 Subject: [PATCH] pass mkdir option on pino/file transport to destination --- file.js | 4 +++- test/transport/core.test.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/file.js b/file.js index 7968c1945..a75366164 100644 --- a/file.js +++ b/file.js @@ -4,7 +4,9 @@ const pino = require('./pino') const { once } = require('events') module.exports = async function (opts = {}) { - const destination = pino.destination({ dest: opts.destination || 1, sync: false }) + const destOpts = { dest: opts.destination || 1, sync: false } + if (opts.mkdir) destOpts.mkdir = true + const destination = pino.destination(destOpts) await once(destination, 'ready') return destination } diff --git a/test/transport/core.test.js b/test/transport/core.test.js index c307ed9c4..a08e98e7a 100644 --- a/test/transport/core.test.js +++ b/test/transport/core.test.js @@ -279,6 +279,27 @@ test('pino.transport with target pino/file', async ({ same, teardown }) => { }) }) +test('pino.transport with target pino/file and mkdir option', async ({ same, teardown }) => { + const folder = '_' + Math.random().toString(36).substr(2, 9) + const destination = join(os.tmpdir(), folder, folder) + const transport = pino.transport({ + target: 'pino/file', + options: { destination, mkdir: true } + }) + teardown(transport.end.bind(transport)) + const instance = pino(transport) + instance.info('hello') + await watchFileCreated(destination) + const result = JSON.parse(await readFile(destination)) + delete result.time + same(result, { + pid, + hostname, + level: 30, + msg: 'hello' + }) +}) + test('pino.transport with target pino-pretty', async ({ match, teardown }) => { const destination = join( os.tmpdir(),