hapi logging compliant to ot-logging standards
Switch branches/tags
Clone or download
Pull request Compare This branch is 2 commits behind opentable:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
tests
.editorconfig
.eslintrc
.gitignore
.nvmrc
.travis.yml
LICENSE
README.md
index.js
package.json

README.md

hapi-ot-logger

OpenTable standard-compliant logging plugin for Hapi.

Build Status Dependency Status devDependency Status npm version

Usage

$ npm i hapi-ot-logger --save
var server = new (require('hapi').Server)();
server.connection({ port: 3000 });

server.register([
    {
        register: require('hapi-ot-logger'),
        options: {
          servicetype: "myservice",
          versions: {
            request: 'v2',
            log: 'v3',
            error: 'v2'
          },
          redis: {
            host: '127.0.0.1',
            port: 6379,
            listname: 'logs'
          },
          console: true,
          payload: false,
          validate: function(log) {
            return log.logname === 'request' && log.headers['user-agent'] !== 'noisy-spider';
          },
          preSend: function(req, log) {
            log.customAttribute = req.context.someAttribute;
          }
        }
    }
], function (err) {
    if (err) {
        console.error('Failed to load plugin:', err);
    }

    server.start();
});

Configuration

  • servicetype - unique service type
  • versions -
    • request - request log version
    • log - diagnostic log version
    • error - error log version
  • redis
    • host - redis server hostname or IP address
    • port - redis server port
    • listname - redis list name
  • console - (optional) enable console output for debugging
  • payload - (optional) include request payload
  • validate - (optional) validates that a message should be logged
  • preSend - (optional) enables modification of log message

Release History

  • v3.2.1 (2016-08-19)
    • disable plugin option validation as it is a breaking change
  • v3.2.0 (2016-08-18)
    • added optional preSend(req, log) function to enable modification of log message
  • v3.1.0 (2015-11-14)
    • ???