Skip to content

Commit

Permalink
Coerce string integer destinations to file descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Nov 20, 2021
1 parent 0433f54 commit d63257d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ const transport = pino.transport({
pino(transport)
```
The `options.destination` property may also be a number to represent a file descriptor. Typically this would be `1` to write to STDOUT or `2` to write to STDERR. If `options.destination` is not set, it defaults to `1` which means logs will be written to STDOUT.
The `options.destination` property may also be a number to represent a filedescriptor. Typically this would be `1` to write to STDOUT or `2` to write to STDERR. If `options.destination` is not set, it defaults to `1` which means logs will be written to STDOUT. If `options.destination` is a string integer, e.g. `'1'`, it will be coerced to a number and used as a file descriptor. If this is not desired, provide a full path, e.g. `/tmp/1`.
The difference between using the `pino/file` transport builtin and using `pino.destination` is that `pino.destination` runs in the main thread, whereas `pino/file` sets up `pino.destination` in a worker thread.
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/transport-string-stdout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

const pino = require('../..')
const transport = pino.transport({
target: 'pino/file',
options: { destination: '1' }
})
const logger = pino(transport)
logger.info('Hello')
12 changes: 12 additions & 0 deletions test/transport/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,18 @@ test('log and exit before ready', async ({ not }) => {
not(strip(actual).match(/Hello/), null)
})

test('string integer destination', async ({ not }) => {
let actual = ''
const child = execa(process.argv[0], [join(__dirname, '..', 'fixtures', 'transport-string-stdout.js')])

child.stdout.pipe(writer((s, enc, cb) => {
actual += s
cb()
}))
await once(child, 'close')
not(strip(actual).match(/Hello/), null)
})

test('pino transport options with target', async ({ teardown, same }) => {
const destination = join(
os.tmpdir(),
Expand Down

0 comments on commit d63257d

Please sign in to comment.