Giter Club home page Giter Club logo

winston-testified-console's Introduction

winston-testified-console

Configures Winston’s Console transport to send all log messages to stderr to keep test output clean.

Travis CI status bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies bitHound Code

Introduction

Good logging is an invaluable mechanism for many software projects, especially those intended to run as local or network services. And increasingly, as technologies like Docker gain in popularity, those messages are commonly sent to the console, rather than to some file.

Automated testing suites are another invaluable mechanism of modern software projects.

But when your software logs to the console, the "noise" from its messages can make your test output difficult to read—particularly if you develop with a watch set up that automatically runs your tests each time you modify one of your source files.

But if you could get all your logging messages to write to stderr, you'd be able to enjoy clean test output by running the tests with a command like this:

# capture log messages to a file
$ npm test 2>./messages.log

# discard log messages entirely
$ npm test 2>/dev/null

And that's what I've designed this package to do for your project's tests. (That is, assuming your project uses Winston for its logging. 😉)

Getting Started

First off, this is , you'll naturally want to add the package to your project:

$ npm i --save-dev winston-testified-console

Assuming your project's test suite already has a "bootstrap" script (if not, and you don't know how to set this up, see here), add the following line amongst its require statements:

require('winston-testified-console')();

And run your tests, sending stderr to /dev/null:

$ env NODE_ENV=testing npm test 2>/dev/null

That was easy, right? At least in theory; your project will likely require a bit more work to get set up, so let's take it from the top.

Configuring Testify

The more complex your project is, the likelier you'll need to do a bit of configuring. The winston-testified-console supports two optional arguments:

  • target, which references what to "testify" console output for. This can be a winston.Logger instance, a winston.Container instance, an array of instance of either type (can be uniform or a mix), and the winston instance itself (default value).

  • isTesting, which is a callback that should return true whenever console output ought to be "testified". The default callback evaulates to true when the NODE_ENV environment variable matches /^test/ (e.g., test, tests, testing, etc).

require('winston-testified-console')(logger, isTestingCb);

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.