Skip to content

Commit

Permalink
Document pino.transport() async startup (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina authored Aug 24, 2021
1 parent cf20170 commit 3ec9946
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion docs/transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,33 @@ pino(transport)
For more details on `pino.transport` see the [API docs for `pino.transport`][pino-transport].
[pino-transport]: /docs/api.md#pino-transport
[sca]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
### Asynchronous startup
The new transports boot asynchronously and calling `process.exit()` before the transport
started will cause logs to not be delivered.
```js
const pino = require('pino')
const transport = pino.transport({
targets: [
{ target: '/absolute/path/to/my-transport.mjs', level: 'error' },
{ target: 'some-file-transport', options: { destination: '/dev/null' }
]
})
const logger = pino(transport)

logger.info('hello')

// If logs are printed before the transport is ready when process.exit(0) is called,
// they will be lost.
transport.on('ready', function () {
process.exit(0)
})
```
## Legacy Transports
Expand Down

0 comments on commit 3ec9946

Please sign in to comment.