Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Clarify how to log both to a custom transport and to stdout #1860

Merged
merged 5 commits into from
Dec 8, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 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.

### Combining transport with writing to an stdout
kibertoad marked this conversation as resolved.
Show resolved Hide resolved

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,7 +257,7 @@ const logger = pino({
pipeline: [{
target: './my-transform.js'
}, {
// Use target: 'pino/file' to write to stdout
// Use target: 'pino/file' with 'options: { destination: 1 }' to write to STDOUT
kibertoad marked this conversation as resolved.
Show resolved Hide resolved
// without any change.
target: 'pino-pretty'
}]
Expand Down Expand Up @@ -363,7 +382,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