Skip to content

Commit

Permalink
pass mkdir option on pino/file transport to destination
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Nov 16, 2021
1 parent d28197f commit 6c285cc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion file.js
Expand Up @@ -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
}
21 changes: 21 additions & 0 deletions test/transport/core.test.js
Expand Up @@ -279,6 +279,27 @@ test('pino.transport with target pino/file', async ({ same, teardown }) => {
})
})

test('pino.transport with target pino/file and mkdir option', { only: true }, 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(),
Expand Down

0 comments on commit 6c285cc

Please sign in to comment.