Skip to content

Commit

Permalink
docs: Clarify how to log both to a custom transport and to stdout (#1860
Browse files Browse the repository at this point in the history
)

Co-authored-by: James Sumners <321201+jsumners@users.noreply.github.com>
  • Loading branch information
kibertoad and jsumners authored Dec 8, 2023
1 parent e71c7fa commit b5effa5
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions docs/transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,25 @@ To consume async iterators in batches, consider using the [hwp](https://github.c
The `close()` function is needed to make sure that the stream is closed and flushed when its
callback is called or the returned promise resolves. Otherwise, log lines will be lost.
### Writing to a custom transport & stdout
In case you want to both use a custom transport, and output the log entries with default processing to STDOUT, you can use 'pino/file' transport configured with `destination: 1`:
```js
const transports = [
{
target: 'pino/file',
options: { destination: 1 } // this writes to STDOUT
},
{
target: 'my-custom-transport',
options: { someParameter: true }
}
]

const logger = pino(pino.transport({ targets: transports })
```
### Creating a transport pipeline
As an example, the following transport returns a `Transform` stream:
Expand Down Expand Up @@ -238,9 +257,10 @@ const logger = pino({
pipeline: [{
target: './my-transform.js'
}, {
// Use target: 'pino/file' to write to stdout
// without any change.
target: 'pino-pretty'
// Use target: 'pino/file' with STDOUT descriptor 1 to write
// logs without any change.
target: 'pino/file',
options: { destination: 1 }
}]
}
})
Expand Down Expand Up @@ -363,7 +383,7 @@ const split = require('split2')

const myTransportStream = new Writable({
write (chunk, enc, cb) {
// apply a transform and send to stdout
// apply a transform and send to STDOUT
console.log(chunk.toString().toUpperCase())
cb()
}
Expand Down

0 comments on commit b5effa5

Please sign in to comment.