npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rill-pino-logger

v1.0.4

Published

pino logging rill middleware

Downloads

9

Readme

rill-pino-logger  Build Status

pino logging rill middleware

Currently the only production logger available for rill.

To our knowledge, rill-pino-logger is the fastest rill logger in town.

Benchmarks

Benchmarks log each request/response pair while returning 'hello world', using autocannon with 100 connections and pipelining set to 1 (rill can't handle pipelining): autocannon -c 100 -p 1 http://localhost:3000.

  • rill-logger: 10529.82 req/sec
  • rill-pino-logger: 11849 req/sec
  • rill-pino-logger (extreme): 12623.64 req/sec
  • rill w/out logger: 17834.55 req/sec

All benchmarks where taken on a Macbook Pro 2013 (2.6GHZ i7, 16GB of RAM).

Benchmarking against rill-logger is an apples vs oranges situation. rill-logger is for development logging, and has extremely simple (non-JSON) output. However, there's currently no other rill loggers to compare against.

Install

npm i rill-pino-logger --save

Example

Request logging

'use strict'

var rill = require('rill')
var logger = require('rill-pino-logger')

var app = rill()
app.use(logger())

app.use(({log, res}) => {
  log.info('something else')
  res.body = 'hello world'
})

app.listen({port: 3000})
$ node --harmony-destructuring example.js | pino
[2016-04-22T11:49:01.388Z] INFO (29134 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": 54687
    }
[2016-04-22T11:49:01.396Z] INFO (29134 on MacBook-Pro-4.local): request completed
    res: {
      "statusCode": 200,
      "header": "HTTP/1.1 200 OK\r\ncontent-type: text/plain; charset=UTF-8\r\ncontent-length: 11\r\nDate: Fri, 22 Apr 2016 11:49: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": 54687
    }

Thrown Error logging

'use strict'

var rill = require('rill')
var logger = require('rill-pino-logger')

var app = new rill()
app.silent = true // disable console.errors
app.use(logger())

app.use(({res}) => {
  res.body = 'hello world'
  throw Error('bang!')
})

app.listen(3000)
$ node --harmony-destructuring error-example.js | pino
[2016-04-22T11:47:49.838Z] ERROR (29124 on MacBook-Pro-4.local): request errored
    res: {}
    err: {
      "type": "Error",
      "message": "BANG",
      "stack": "Error: BANG\n    at Error (native)\n    at /Users/davidclements/z/nearForm/rill-pino-logger/error-example.js:11:9\n    at dispatch (/Users/davidclements/z/nearForm/rill-pino-logger/node_modules/rill/node_modules/@rill/chain/index.js:28:32)\n    at next (/Users/davidclements/z/nearForm/rill-pino-logger/node_modules/rill/node_modules/@rill/chain/index.js:29:18)\n    at pino (/Users/davidclements/z/nearForm/rill-pino-logger/logger.js:12:12)\n    at dispatch (/Users/davidclements/z/nearForm/rill-pino-logger/node_modules/rill/node_modules/@rill/chain/index.js:28:32)\n    at chained (/Users/davidclements/z/nearForm/rill-pino-logger/node_modules/rill/node_modules/@rill/chain/index.js:16:12)\n    at Server.handleIncommingMessage (/Users/davidclements/z/nearForm/rill-pino-logger/node_modules/rill/src/index.js:56:5)\n    at emitTwo (events.js:100:13)\n    at Server.emit (events.js:185:7)"
    }
    req: {
      "id": 1,
      "method": "GET",
      "url": "/",
      "headers": {
        "host": "localhost:3000",
        "user-agent": "curl/7.43.0",
        "accept": "*/*"
      },
      "remoteAddress": "::1",
      "remotePort": 54686
    }
[2016-04-22T11:47:49.844Z] INFO (29124 on MacBook-Pro-4.local): request completed
    res: {
      "statusCode": 200,
      "header": "HTTP/1.1 200 OK\r\ncontent-type: text/plain; charset=UTF-8\r\ncontent-length: 11\r\nDate: Fri, 22 Apr 2016 11:47:49 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": 54686
    }

Browser

In keeping with Rill's isomorphic nature, rill-pino-logger works just fine in the browser.

browserify example.js > eg.js

index.html:

<script src=eg.js></script>

If we were to open index.html we would see the examples messages in the console.

If we wish to log via some other mechanism, we can pass a stream:

var websocket = require('websocket-stream')
app.use(logger(websocket('http://localhost:3000', [])))

This would send all logs over websocket to http://localhost:3000.

API

rill-pino-logger has the same options as pino rill-pino-logger will log when a request finishes or errors.

Along with automated request logging, the pino logger facilitates manual logging by adding the pino logger instance to the the context object:

  app.use(({log}, next) => {
    log.info('test')
    return next()
  })

License

MIT