Git Product home page Git Product logo

simplelogger's Introduction

THIS IS DEAD

It lives in my core-utils modules instead.

simplelogger

A VERY simplistic console.log replacement to enable filtering

Usage:

const logger = require('simplelogger');
const log = logger.bind('name');
// logger.disable('name')

log("Here's my message");
log(`Or maybe ${this} instead...`);
log(this);

logger.disable('name');
log("This won't get disabled, now");

if (logger.isEnabled('name')) {
  doSomethingSlowAndBig();
}
logger('otherName', this);
logger('otherName', "will also work");
logger('name', "and this won't get displayed now");
log('But just use it this way');
log('then you can turn it on and off easily');

API:

The default export is a log function that takes an initial 'labelling' parameter, which is only used to to control whether the log message is displayed. Thus, you can just use the thing like this:

const logger = require('simplelogger');
logger(1234, "<- that thing won't ever get logged");

But that's not really the point.

The point is to use logger.bind to enable you to switch all your console.log(...) commands over to just log(...) commands and then be able to turn them on and off trivially.

simplelogger.bind(name) returns a function that works just like console.log, but can be enabled or disabled using the rest of the API.

simplelogger.disable(name) will disable logging for any logger bound to that name.

simplelogger.enable(name) will enable logging for any logger bound to that name.

simplelogger.defaultToOff() makes the logger only show logs for names which have been explicitly enabled using the enable API.

simplelogger.defaultToOn() makes the logger show any logs for names unless they have been explicitly disabled using the disable API. This is the default mode of operation.

simplelogger.isDisabled(name) returns true if name has logging disabled.

simplelogger.isEnabled(name) returns true if name has logging enabled.

simplelogger's People

Contributors

kevinfrei avatar

Watchers

 avatar  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.