Skip to content

Commit cc0902a

Browse files
authoredOct 23, 2021
docs: describe how to use with non-serializable options (#252)
1 parent 4b93241 commit cc0902a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
 

‎Readme.md

+34
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,40 @@ logger.info('hi')
130130

131131
See the [Options](#options) section for all possible options.
132132

133+
### Handling non-serializable options
134+
135+
Using the new [pino v7+
136+
transports](https://getpino.io/#/docs/transports?id=v7-transports) not all
137+
options are serializable, for example if you want to use `messageFormat` as a
138+
function you will need to wrap `pino-pretty` in a custom module.
139+
140+
Executing `main.js` below will log a colorized `hello world` message using a
141+
custom function `messageFormat`:
142+
143+
```js
144+
// main.js
145+
const pino = require('pino')
146+
147+
const logger = pino({
148+
transport: {
149+
target: './pino-pretty-transport',
150+
options: {
151+
colorize: true
152+
}
153+
},
154+
})
155+
156+
logger.info('world')
157+
```
158+
159+
```js
160+
// pino-pretty-transport.js
161+
module.exports = opts => require('pino-pretty')({
162+
...opts,
163+
messageFormat: (log, messageKey) => `hello ${log[messageKey]}`
164+
})
165+
```
166+
133167
<a id="options"></a>
134168
### Options
135169

0 commit comments

Comments
 (0)
Please sign in to comment.