JSPM

  • Created
  • Published
  • Downloads 69856
  • Score
    100M100P100Q152917F
  • License MIT

Hapi plugin for the Pino logger

Package Exports

  • hapi-pino

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 (hapi-pino) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hapi-pino

Hapi plugin for the Pino logger. It logs in JSON for easy post-processing. It is faster than good console logger by a 25% factor, which increases to 40% when using extreme mode). Using hapi-pino in extreme mode allows the "hello world" example to handle 40% more throughput than good.

Install

npm i hapi-pino --save

Usage

'use strict'

const Hapi = require('hapi')

// Create a server with a host and port
const server = new Hapi.Server()
server.connection({
  host: 'localhost',
  port: 3000
})

// Add the route
server.route({
  method: 'GET',
  path: '/',
  handler: function (request, reply) {
    request.logger.info('In handler %s', request.path)
    return reply('hello world')
  }
})

server.register({
  register: require('.').register,
  options: {
    extreme: false
  }
}, (err) => {
  if (err) {
    console.error(err)
    process.exit(1)
  }

  server.app.logger.warn('Pino is registered')
  server.logger().info('another way for accessing it')

  // Start the server
  server.start((err) => {
    if (err) {
      console.error(err)
      process.exit(1)
    }
  })
})

Acknowledgements

This project was kindly sponsored by nearForm.

License

MIT