restify-pino-logger

pino logging restify middleware

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
restify-pino-logger
3.0.06 years ago8 years agoMinified + gzip package size for restify-pino-logger in KB

Readme

restify-pino-logger  Build Status
pino logging restify middleware
To our knowledge, restify-pino-logger is the fastest restify logger in town.

Benchmarks

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/sec
  • restify-bunyan-logger: 6306.73 req/sec
  • restify-logger: 7485.28 req/sec
  • restify-pino-logger: 8207.46 req/sec
  • restify-pino-logger (extreme): 8789.28 req/sec
  • restify-pino-logger (without restify): 22240.73 req/seq
  • restify-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.

Install

npm i restify-pino-logger --save

Example

'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
    }

API

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.

License

MIT