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

laabr

v6.1.3

Published

well-formatted, extendable pino logger for hapi.js

Downloads

6,357

Readme

laabr logo

well-formatted, extendable pino logger for hapi.js

Booyah! Works like a charm.

Marcus Pöhls

Travis node npm standard npm Coverage Status

  1. Introduction
  2. Installation
  3. Usage
  4. API ⇗
  5. Tokens ⇗
  6. Formats ⇗
  7. Presets ⇗
  8. Example
  9. Developing and Testing
  10. 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. laabr is the Swabian translation for talking.

The modules standard and ava are used to grant a high quality implementation.

Compatibility

| Major Release | hapi.js version | hapi-pino version | node version | | --- | --- | --- | --- | | v6 | >=18.4 @hapi/hapi | >= 6.3 | >=12 | | v5.1 | >=18.3.1 @hapi/hapi | >= 5.4 | >=8 | | v5 | >=18 hapi | >= 5.4 | >=8 | | v4 | >=17 hapi | >= 5.1 | >=8 | | v3 | >=17 hapi | >= 3 | >=8 | | v2 | >=13 hapi | >= 1.6 | >=6 |

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

laabr screen

Installation

For installation use the npm ⇗:

$ npm install --save laabr

or clone the repository:

$ git clone https://github.com/felixheck/laabr

Usage

Import

First you have to import the module:

const laabr = require('laabr');

Create hapi server

Afterwards create your hapi server if not already done:

const hapi = require('@hapi/hapi');
const server = hapi.server({
  port: 8888,
  host: 'localhost',
});

Registration

Finally register the plugin and set the correct options:

await server.register({
  plugin: laabr,
  options: {},
});

Example

Take a look at several more examples ⇗.

Code

const hapi = require('@hapi/hapi');
const laabr = require('laabr');

const server = hapi.server({ port: 3000 });

const options = {
  formats: { onPostStart: ':time :start :level :message' },
  tokens: { start:  () => '[start]' },
  indent: 0
};

server.route([
  {
    method: '*',
    path: '/response',
    handler() {
      return 'hello world';
    }
  },
  {
    method: 'GET',
    path: '/error',
    handler () {
      throw new Error('foobar');
    }
  }
]);

(async () => {
  try {
    await server.register({
      plugin: laabr,
      options
    });
    await server.start();
    console.log('Server started successfully');
  } catch (err) {
    console.error(err);
  }
})();

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 stopped

Developing and Testing

First you have to install all dependencies:

$ npm install

To execute all unit tests once, use:

$ npm test

or to run tests based on file watcher, use:

$ npm start

To get information about the test coverage, use:

$ npm run coverage

Contribution

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.