pino logging restify middleware
To our knowledge, restify-pino-logger
is the fastest restify logger in town.
Benchmarks log each request/response pair while returning
'hello world'
, using
autocannon with 100
connections and 10 pipelined requests (autocannon -c 100 -p 10 http://localhost:3000
).
restify.auditLogger
+bunyan
: 5483.82 req/secrestify-bunyan-logger
: 6306.73 req/secrestify-logger
: 7485.28 req/secrestify-pino-logger
: 8207.46 req/secrestify-pino-logger
(extreme): 8789.28 req/secrestify-pino-logger
(without restify): 22240.73 req/seqrestify-pino-logger
(without restify and extreme): 25536 req/sec
All benchmarks where taken on a Macbook Pro 2013 (2.6GHZ i7, 16GB of RAM).
Whilst we're comparing restify-pino-logger
against restify-logger
this isn't really a fair contest.
restify-logger
sits on top of morgan.
Morgan doesn't support logging arbitrary data, nor does it output JSON. Further Morgan uses a form of eval
to achieve high speed logging. Whilst probably safe, using eval
at all tends to cause concern, particular when it comes to server-side JavaScript.
The fact that restify-pino-logger
achieves higher throughput with JSON logging and arbitrary data, without using eval
, serves to emphasise the high-speed capabilities of restify-pino-logger
.
With restify-pino-logger
you can have features, safety and speed.
npm i restify-pino-logger --save
'use strict'
var restify = require('restify')
var server = restify.createServer({name: 'app'})
server.use(require('restify-pino-logger')())
server.get('/', function (req, res) {
req.log.info('something else')
res.send('hello world')
})
server.listen(3000)
$ node example.js | pino
[2016-04-20T20:50:01.260Z] INFO (11809 on MacBook-Pro-4.local): something else
req: {
"id": 1,
"method": "GET",
"url": "/",
"headers": {
"host": "localhost:3000",
"user-agent": "curl/7.43.0",
"accept": "*/*"
},
"remoteAddress": "::1",
"remotePort": 55295
}
[2016-04-20T20:50:01.267Z] INFO (11809 on MacBook-Pro-4.local): request completed
res: {
"statusCode": 200,
"header": "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 13\r\nDate: Wed, 20 Apr 2016 20:50:01 GMT\r\nConnection: keep-alive\r\n\r\n"
}
responseTime: 8
req: {
"id": 1,
"method": "GET",
"url": "/",
"headers": {
"host": "localhost:3000",
"user-agent": "curl/7.43.0",
"accept": "*/*"
},
"remoteAddress": "::1",
"remotePort": 55295
}
restify-pino-logger
has the same options of
pino, look at them there.
restify-pino-logger
attaches some listeners to the request, so that
it will log when the request is completed.
MIT