Package Exports
- pino-http
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (pino-http) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
pino-http 
High-speed HTTP logger for Node.js
To our knowledge, pino-http is the fastest HTTP logger in town.
Benchmarks
Benchmarks log each request/response pair while returning
'hello world', using
autocannon with 100
connections and 10 pipelined requests.
http-ndjson(equivalent info): 7730.73 req/sechttp-ndjson(standard minimum info): 9522.37 req/secpino-http: 21496 req/secpino-http(extreme): 25770.91 req/sec- no logger: 46139.64 req/sec
All benchmarks where taken on a Macbook Pro 2013 (2.6GHZ i7, 16GB of RAM).
Install
npm i pino-http --saveExample
'use strict'
var http = require('http')
var server = http.createServer(handle)
var logger = require('pino-http')()
function handle (req, res) {
logger(req, res)
req.log.info('something else')
res.end('hello world')
}
server.listen(3000)$ node example.js | pino
[2016-03-31T16:53:21.079Z] INFO (46316 on MBP-di-Matteo): something else
req: {
"id": 1,
"method": "GET",
"url": "/",
"headers": {
"host": "localhost:3000",
"user-agent": "curl/7.43.0",
"accept": "*/*"
},
"remoteAddress": "::1",
"remotePort": 64386
}
[2016-03-31T16:53:21.087Z] INFO (46316 on MBP-di-Matteo): request completed
res: {
"statusCode": 200,
"header": "HTTP/1.1 200 OK\r\nX-Powered-By: restify\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 11\r\nETag: W/\"b-XrY7u+Ae7tCTyyK7j1rNww\"\r\nDate: Thu, 31 Mar 2016 16:53:21 GMT\r\nConnection: keep-alive\r\n\r\n"
}
responseTime: 10
req: {
"id": 1,
"method": "GET",
"url": "/",
"headers": {
"host": "localhost:3000",
"user-agent": "curl/7.43.0",
"accept": "*/*"
},
"remoteAddress": "::1",
"remotePort": 64386
}API
pinoHttp([options], [stream])
pino-http has the same options as pino.
pino-http attaches listeners to the request, in order to log when the request completes
pino-http can reuse a pino instance if passed with the logger
property:
'use strict'
var http = require('http')
var server = http.createServer(handle)
var pino = require('pino')()
var logger = require('pino-http')({
logger: pino
})
function handle (req, res) {
logger(req, res)
req.log.info('something else')
res.end('hello world')
}
server.listen(3000)Example:
'use strict'
var pino = require('pino-http')
var logger = pino({
serializers: {
req: pino.stdSerializers.req,
res: pino.stdSerializers.res
}
})pinoHttp.stdSerializers.req
Generates a JSONifiable object from the HTTP request object passed to
the createServer callback of Node's HTTP server.
It returns an object in the form:
{
pid: 93535,
hostname: 'your host',
level: 30,
msg: 'my request',
time: '2016-03-07T12:21:48.766Z',
v: 0,
req: {
id: 42,
method: 'GET',
url: '/',
headers: {
host: 'localhost:50201',
connection: 'close'
},
remoteAddress: '::ffff:127.0.0.1',
remotePort: 50202
}
}pinoHttp.stdSerializers.res
Generates a JSONifiable object from the HTTP response object passed to
the createServer callback of Node's HTTP server.
It returns an object in the form:
{
pid: 93581,
hostname: 'myhost',
level: 30,
msg: 'my response',
time: '2016-03-07T12:23:18.041Z',
v: 0,
res: {
statusCode: 200,
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'
}
}Team
Matteo Collina
https://www.npmjs.com/~matteo.collina
https://twitter.com/matteocollina
David Mark Clements
https://github.com/davidmarkclements
https://www.npmjs.com/~davidmarkclements
https://twitter.com/davidmarkclem
License
MIT