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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hapi-madero

v0.2.14

Published

A HapiJS plugin for writing logs to files

Readme

hapi-madero

Build Status Dependencies Status

NPM

A HapiJS plugin for writing logs to files

HapiJS plugin for writing logs to files. It creates 5 different files, depending on the log type ('info', 'error', 'warning', 'request', 'plugin'). I find it useful for services like splunk which can read logs from the server directly.

Installing

npm install hapi-madero

Usage

Here is a snippet of a basic setup:

// Deps =========================================
const Hapi = require('hapi');
const Madero = require('hapi-madero');

// Server =======================================
const server = new Hapi.Server({ debug: false });

// Server Connection ============================
server.connection({ port: 3000, host: 'localhost' });

// Madero Options ===============================
const maderoOptions = { path: './logs' };

// Adding Madero Plugin =========================
server.register({ register: Madero, options: maderoOptions }, err => {

	if (err) {
        console.log('[ERROR]:', 'Failed loading plugin: hapi-madero,', err);
    }

    server.route({
        method: 'GET',
        path: '/',
        handler: (request, reply) => {

            request.log(['test'], { message: 'test', foo: 'bar' });
            return reply('ok')
        }
    });

    // Logging all responses
    server.on('response', (request) => {

        const response = request.response;
        let statusCode = response.statusCode;
        let message = 'Auto request log';
        let entry = { statusCode, message };
        let error;

        if (response.isBoom) {
            statusCode = response.output.payload.statusCode;
            message = response.message;
            error = response.output.payload;
            entry = { statusCode, message, error };

            // Logs error
            return request.log(['error', 'boom'], entry);
        }

        // Log every request
        return request.log(['info'], entry);
    });

    server.start(err => {

        if (err) {
            server.plugins['hapi-madero'].console(err, 'error');
        }
        server.log(['info', 'app', 'start'], {
            message: `Hapi-Madero server started`,
            port: server.info.port,
            protocol: server.info.protocol,
            uri: server.info.uri,
            address: server.info.address
        });
    });
});

Plugin Options

path - String

Madero needs to know where to save the files, this will tell madero where the log files will be saved. I.E.: ./logs will create a directory in the project root called 'logs'. Defaults to path.resolve(path.dirname(require.main.filename), './logs') (which will create the directory where the main file is run)

stopTimeoutMsec - Number

Overrides the timeout in millisecond before forcefully terminating a connection. Defaults to 15000 (15 seconds)

silent - Boolean

If you do not want to see every log in the console. Defaults to false

signals - Boolean

Whether you want madero to handle SIGTERM or SIGINT. Defaults to true

exceptions - Boolean

Whether you want madero to handle uncaughtException or unhandledRejection. Defaults to true

timestampKey - String

In case you need to specify the timestamp key for the events, you can change it here. Defaults to @timestamp

unixStamp - Boolean

By default, each event timestamp is set to a ISO string: YYYY-MM-DDTHH:mm:ss.sssZ, changing this to true will change to a unix stamp of 13 numbers.

Plugin Methods

write (options, [callback])

options - required - Object

Recieves a the following:

  • async - Boolean - Wether to write to file async or not
  • request - Object - The request object
  • entry - Object - The entry that will be written to file. This expects the following:
    • message - required - String - Entry message
    • tags - required - Array - Array of strings used to identify the event. Tags are used instead of log levels and provide a much more expressive mechanism for describing and filtering events.
    • error - Object - An error object
    • data - Object - Any additional data to be saved with the entry
callback - function

Called once it has finshed writing to file

console (data, [type, [callback]])

data - Object

This will be the object that you want to log to console

type - String

Can be one of: error, info, warn. Defaults to info

callback - function

Called once it has finshed logging to console

License

This project is licensed under the MIT License - see the LICENSE.md file for details