rollover
v1.0.0
Published
hapi 17+ rollbar plugin
Downloads
7
Maintainers
Readme
rollover
rollover
rollover
, is a hapi 17+ plugin used for Rollbar reporting.
Basic Usage
'use strict';
const Hapi = require('hapi');
const Rollover = require('rollover');
const server = Hapi.server();
await server.register([
{ plugin: Rollover, options: { rollbar: your_rollbar_token } }
]);
server.route([
{
method: 'GET',
path: '/foo',
handler (request, h) {
request.log(['log'], 'request.log() -> rollbar.log()');
request.log(['log', 'error'], 'request.log() -> rollbar.error()');
throw new Error('throw_err');
}
}
]);
Live Testing
By default rollover
's test suite mocks calls to the Rollbar service. To make real Rollbar calls in the test suite, use the following command:
ROLLOVER_ROLLBAR_TOKEN=your_rollbar_token npm test
Plugin Options
rollover
supports the following configuration options during plugin registration.
rollbar
- Rollbar configuration that is passed directly to theRollbar()
constructor. This option is required.reportErrorResponses
(Boolean) - Whentrue
, a hapionPreResponse
handler is created which sendsError
responses to Rollbar. Defaults totrue
.reportRequestLogs
(Boolean) - Whentrue
, a hapi'request'
event handler is created which sendsrequest.log()
data to Rollbar. The Rollbar report level can be controlled via therequest.log()
tags'critical'
,'error'
,'warning'
,'info'
, and'debug'
. If none of these tags are provided, Rollbar's default log level is used. Defaults totrue
.reportServerLogs
(Boolean) - Whentrue
, a hapi server'log'
event handler is created which sendsserver.log()
data to Rollbar. The Rollbar report level can be controlled via therequest.log()
tags'critical'
,'error'
,'warning'
,'info'
, and'debug'
. If none of these tags are provided, Rollbar's default log level is used. Defaults totrue
.silenceRollbarLogger
(Boolean) - Whentrue
, Rollbar'sconsole
logger is silenced. Defaults totrue
.exposedName
(String) -rollover
exposes aRollbar
instance, making it possible to implement custom usage throughout an application. By default, this instance is exposed on the hapi server asserver.plugins.rollover.rollbar
. This option allows the name to be changed to something other thanrollbar
.