Skip to content

Commit 6b96119

Browse files
committed
Added serializers in the docs.
1 parent 031b27e commit 6b96119

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ This produces:
6363
* <a href="#info"><code>logger.<b>info()</b></code></a>
6464
* <a href="#debug"><code>logger.<b>debug()</b></code></a>
6565
* <a href="#trace"><code>logger.<b>trace()</b></code></a>
66+
* <a href="#reqSerializer"><code>pino.stdSerializers.<b>req</b></code></a>
67+
* <a href="#resSerializer"><code>pino.stdSerializers.<b>res</b></code></a>
6668

6769
<a name="constructor"></a>
6870
### pino([opts], [stream])
@@ -72,9 +74,28 @@ Returns a new logger. Allowed options are:
7274
* `safe`: avoid error causes by circular references in the object tree,
7375
default `true`
7476
* `name`: the name of the logger, default `undefined`
77+
* `serializers`: an object containing functions for custom serialization
78+
of objects. These functions should return an jsonificable object and
79+
they should never throw.
7580

7681
`stream` is a Writable stream, defaults to `process.stdout`.
7782

83+
Example:
84+
85+
```js
86+
'use strict'
87+
88+
var pino = require('pino')
89+
var instance = pino({
90+
name: 'myapp',
91+
safe: true,
92+
serializers: {
93+
req: pino.stdSerializers.req
94+
res: pino.stdSerializers.res
95+
}
96+
}
97+
```
98+
7899
<a name="level"></a>
79100
### logger.level
80101
@@ -140,6 +161,59 @@ object, all its properties will be included in the JSON line.
140161
If more args follows `msg`, these will be used to format `msg` using
141162
[`util.format`](https://nodejs.org/api/util.html#util_util_format_format)
142163
164+
<a name="reqSerializer"></a>
165+
### pino.stdSerializers.req
166+
167+
Function to generate a jsonificable object out of an HTTP request from
168+
node HTTP server.
169+
170+
It returns an object in the form:
171+
172+
```js
173+
{
174+
pid: 93535,
175+
hostname: 'your host',
176+
level: 30,
177+
msg: 'my request',
178+
time: '2016-03-07T12:21:48.766Z',
179+
v: 0,
180+
req: {
181+
method: 'GET',
182+
url: '/',
183+
headers: {
184+
host: 'localhost:50201',
185+
connection: 'close'
186+
},
187+
remoteAddress: '::ffff:127.0.0.1',
188+
remotePort: 50202
189+
}
190+
}
191+
```
192+
193+
<a name="resSerializer"></a>
194+
### pino.stdSerializers.res
195+
196+
Function to generate a jsonificable object out of an HTTP
197+
response from
198+
node HTTP server.
199+
200+
It returns an object in the form:
201+
202+
```js
203+
{
204+
pid: 93581,
205+
hostname: 'myhost',
206+
level: 30,
207+
msg: 'my response',
208+
time: '2016-03-07T12:23:18.041Z',
209+
v: 0,
210+
res: {
211+
statusCode: 200,
212+
header: 'HTTP/1.1 200 OK\r\nDate: Mon, 07 Mar 2016 12:23:18 GMT\r\nConnection: close\r\nContent-Length: 5\r\n\r\n'
213+
}
214+
}
215+
```
216+
143217
<a name="benchmarks"></a>
144218
## Benchmarks
145219

0 commit comments

Comments
 (0)