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

well-formatted, extendable pino logger for hapi.js
Booyah! Works like a charm.
- Introduction
- Installation
- Usage
- API ⇗
- Tokens ⇗
- Formats ⇗
- Presets ⇗
- Example
- Developing and Testing
- Contribution
Introduction
laabr is a well-formatted pino ⇗ logger for hapi.js ⇗ which is based on the plugin hapi-pino ⇗. It enables optionally to log in JSON for easy post-processing. It listens to various hapi.js events ⇗ and logs in a well-formatted manner. Therefor it is possible to define custom formats alike the morgan ⇗ ones or make use of available presets. Additionally it enables to define own tokens which could be used in custom formats. Finally the plugin provides well integrated correlation identifiers based on the module correlation-id ⇗.
This plugin is implemented in ECMAScript 6 without any transpilers like babel.
Additionally standard and ava are used to grant a high quality implementation.
laabr is the Swabian translation for talking.
laabr vs. hapi-pino
First of all laabr extends the hapi-pino plugin. So it is possible to use laabr in an almost identical manner like hapi-pino. This plugin provides further features which probably decelerates the logging a bit, but it should be faster than the alternatives anyway. The following features are provided:
- Easy out of the box usage
- Context-sensitive colorization
- Customizable identation for JSON strings
- Wide range of preset tokens ⇗ to extract and compose data as needed
- Preset formats ⇗ combining useful tokens for an easy start
- Possibility to add own format presets ⇗ for an easy reuse
- Easily customizable tokens & formats
- Override several
console⇗ logging methods - In despite of everything it is possible to preformat ⇗ & postformat ⇗ data, e.g. to filter sensitive data
- Optional integration of correlation ids ⇗

Installation
For installation use the Node Package Manager ⇗:
$ npm install --save laabror clone the repository:
$ git clone https://github.com/felixheck/laabrAlternatively use the Yarn Package Manager ⇗:
$ yarn add laabrUsage
Import
First you have to import the module:
const laabr = require('laabr');Create hapi server
Afterwards create your hapi server and the corresponding connection if not already done:
const server = new Hapi.Server();
server.connection({
port: 8888,
host: 'localhost',
});Registration
Finally register the plugin and set the correct options:
server.register({
register: laabr.plugin,
options: {},
}, function(err) {
if (err) {
throw err;
}
});Example
Take a look at several more examples ⇗.
Code
const Hapi = require('hapi');
const laabr = require('laabr');
const server = new Hapi.Server()
server.connection({ port: 3000, host: 'localhost' })
laabr.format('onPostStart', ':time :start :level :message')
laabr.token('start', () => '[start]')
server.route([
{
method: '*',
path: '/response',
handler (req, reply) {
reply('hello world')
}
},
{
method: 'GET',
path: '/error',
handler (req, reply) {
reply(new Error('foobar'))
}
}
])
process.on('SIGINT', () => {
server.stop().then((err) => {
process.exit((err) ? 1 : 0)
})
})
server.register({
register: laabr.plugin,
options: {
indent: 0
}
})
.then(() => server.start())
.catch(console.error)
server.log('info', 'did you mean "foobar"?')Output
// (1) `log`
$ {"message":"did you mean \"foobar\"?","timestamp":1499352305938,"level":"info"}
// (2) `onPostStart`
$ 1499352305956 [start] info server started
// (3) `response` – calling `/response`
$ 1499352307927 GET 127.0.0.1 /response 200 {} (25 ms)
// (4) `request-error` & `response` – calling `/error`
$ {"error":"foobar","timestamp":1499352320071,"level":"warn"}
$ 1499352320072 GET 127.0.0.1 /error 500 {} (3 ms)
// (5) `onPostStop` – Pressing `Ctrl + C`
$ 1499352325077 info server stoppedDeveloping and Testing
First you have to install all dependencies:
$ npm installTo execute all unit tests once, use:
$ npm testor to run tests based on file watcher, use:
$ npm startTo get information about the test coverage, use:
$ npm run coverageContribution
Fork this repository and push in your ideas.
Do not forget to add corresponding tests to keep up 100% test coverage.
For further information read the contributing guideline.