Coder Social home page Coder Social logo

good-winston's Introduction

good-winston

A hapi good stream to winston logging adapter.

This stream clones good-console but terminates logs to winston.

Installation

  $ npm install -S winston
  $ npm install -S good-winston

Usage

To use the GoodWinston you simply need to require it and pass it a winston logger instance -

const GoodWinston = require('good-winston');
const winston = require('winston');
const goodWinstonStream = new GoodWinston({ winston });

The following config options are availble to configure GoodWinston:

  • config - required configuration object with the following keys
    • winston - winston logger (required).
    • level - Log level for internal events -
      • error - Map all good error events to this winston level (Default error).
      • other - Map all other good events to this winston level (Default info).
      • ops - Map all good ops events to this winston level (Default info).
      • response - Map all good response events to this winston level (Default info).
      • request - Map all good request events to this winston level (Default undefined so level will be deduced from tags).
    • format - MomentJS format string. Defaults to 'YYMMDD/HHmmss.SSS'.
    • utc - boolean controlling Moment using utc mode or not. Defaults to true.
    • color - a boolean specifying whether to output in color. Defaults to true.

Integrating with good

As with any good stream new good-winston you can either pass the created stream to good -

const GoodWinston = require('good-winston');
const goodWinstonStream = new GoodWinston({ winston: require('winston') });
const good = require('good');


server.register({
  register: good,  
  options: {
    reporters:{
      winston: [ goodWinstonStream ]
    }
}, err => {
  if (err) {
    throw err;
  }
});

Or you can have good initiate the stream from the module for you -

const winston = require('winston');
const good = require('good');

server.register({
  register: good,  
  options: {
    reporters:{
      winston: [{
        module: 'good-winston',
        args: [{ winston }]
      }]
    }
}, err => {
  if (err) {
    throw err;
  }
});

Using Tags and Levels

Using the level parameter in the config variable you can set the log level for internal events that are not controlled from your code (like ops and response) but for logs where are called from your code you should set a tag with the appropriate log level .good-winston will iterate the tag and will set the level by the first tag that matches the winston logger available levels. If no appropriate level was found other level will be used

good-winston's People

Contributors

lancespeelmon avatar yonjah avatar jcteague avatar esatterwhite avatar

Watchers

Mike Caisey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.