@hemor/hapi-good-winston

2.1.0 • Public • Published

hapi-good-winston

A good reporter to send and log events with winston

npm npm license

CircleCI Dependency Status

Issues PR

Disclaimer

Hapi-good-winston 2 only support good >= 8 and hapi >= 17

  • Use 1.* for version prior to hapi v17

Installation

$ npm install --save hapi-good-winston

Usage

import { Server } from 'hapi';
import winston from 'winston';
import goodWinston from 'hapi-good-winston';

const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    transports: [new winston.transports.Console()],
});

const server = new Server();

// Set winston minimum log level to debug
// winston.level = 'debug';

// Only the 'response' and 'error' event levels will be overwritten
const goodWinstonOptions = {
    levels: {
        response: 'debug',
        error: 'info',
    },
};

const options = {
    ops: {
        interval: 1000,
    },
    reporters: {
        // Simple and straight forward usage
        winston: [goodWinston(logger)],
        // Adding some customization configuration
        winstonWithLogLevels: [goodWinston(logger, goodWinstonOptions)],
        // This example simply illustrates auto loading and instantiation made by good
        winston2: [
            {
                module: 'hapi-good-winston',
                name: 'goodWinston',
                args: [logger, goodWinstonOptions],
            },
        ],
    },
};

server
    .register({
        plugin: require('good'),
        options,
    })
    .then(() => {
        return server.start();
    })
    .then(() => {
        console.info(`Server started at ${server.info.uri}`);
    });

Links

License

MIT

Dependents (0)

Package Sidebar

Install

npm i @hemor/hapi-good-winston

Weekly Downloads

1

Version

2.1.0

License

MIT

Unpacked Size

16.7 kB

Total Files

7

Last publish

Collaborators

  • hemor