Giter Site home page Giter Site logo

noop-console's Introduction

Noop Console

JavaScript nop console, replace console method calls with no-operations.

Useful to silence all logging- i.e. during testing- or just from one module.

Getting Started

Install the module with: npm install noop-console

Examples

Mute global console:

require('noop-console')(console);

Later if you want to restore the console, you can restore it by calling:

console._restore();

If you create abstract modules with a logger property that references the standard console so that the actual logger implementation is defined outside the module, you can override this with a noop-console.

module.js:

function MyModule(){}
MyModule.prototype.logger = console;

my_test.js:

var MyModule = require('./module');
MyModule.prototype.logger = require('noop-console')();

Release History

  • 2019-01-11 v.0.5.0: Small refactoring and clean up.
  • 2016-11-24 v.0.4.0: Added _restore.
  • 2016-11-23 v.0.3.0: Take in console reference to mute.
  • 2016-09-02 v.0.1.0: Initial release.

License

Copyright (c) 2016 goliatone
Licensed under the MIT license.

noop-console's People

Contributors

goliatone avatar

Watchers

 avatar James Cloos avatar

noop-console's Issues

stack overflow in logger function

Overwrite to:

while (method = methods.pop()) {
        if (console[method] ) {
            con[method] = (function(m) {
                const f = console[m];
                return function() {
                    f.apply(null, arguments);
                };
            })(method);
        } else {
            //e.g. node v6 does not have a debug method but v10 does.
            if (strict) throw new Error('Console does not have method' + method);
            else console.error('Console does not have metohd ' + method);
        }
    }

Env based return

Provide a method to return noop or logger based on environment, something like:

const noconsole = require('noop-console');
const noop = process.env.NODE_ENV === 'production' ? noconsole() : noconsole.logger();

Overwriting native console

This is not directly caused by this module, but the result of overwriting a MyClass.prototype.logger = console;
We should look for a way to do this sensibly and make a recommendation.

If we do a noopConsole(console); then we need to overwrite the console smartly. Read the source and figure how to use it in application-core mute console

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.