npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

owm

v1.0.2

Published

OnlyWhatMatters - Enabling console output by levels (log, warn, error, all)

Downloads

4

Readme

Only What Matters - Simple Level Logger

This module/script enables the user to set his own output level for the console. It works for node and for browsers (>IE11) and it manages console.(debug|error|info|log|trace|warn) methods only.

How to use

npm install -save owm

Or in browser

<script src="path/of/owm/index.js"></script>
<script>
var logger = new OWM('l');
logger.log('It works!');
logger.info('This is hidden');
</script>

The input parameter(s)

Each parameter could be provided in exclusion (or inclusion) mode by prepending (or not) a "-" dash before the letter corresponding the desired level.

Accepted values (as single concatenated string, as multiple strings or as array of strings)

  • "d": enabled debug method
  • "-d": disable debug method
  • "e": enabled error method
  • "-e": disable error method
  • "i": enabled info method
  • "-i": disable info method
  • "l": enabled log method
  • "-l": disable log method
  • "t": enabled trace method
  • "-t": disable trace method
  • "w": enabled warn method
  • "-w": disable warn method
  • "a": shortcut for "deiltw". This enables all the methods above (d, e, i, l, t, w). IMPORTANT: This is the default value.
  • "-a": shortcut for "-d-e-i-l-t-w". This disables all the methods above (d, e, i, l, t, w)

If "a" is present but not "-a", all methods are enabled. If "-a" is present, all methods are disabeld. In all the other cases, order matters: latest wins.

Extended "human readable" values are also accepted:

  • (-)all
  • (-)log / (-)logs
  • (-)err / (-)error / (-)errors
  • (-)warn / (-)warning / (-)warnings

They all will be converted in (-)(a|l|e|w).

Special methods: options, reset, __noSuchMethod__

var logger = new OWM(); // enables all ('a' is the default value)
logger.options('l'); // enables log method only
logger.reset(); // shortcut for logger.options() with no parameters: re-enable all primitive methods
logger.options('le'); // enables log and error methods only;

/* Customizable behavior for unexistent methods (as prototype or not) */
OWM.prototype.__noSuchMethod__ = function(name, args){
    this.error(`This method doesn't exists: ${name}.`); 
};
logger.newMethod('Test me'); // output: "This method doesn't exists: newMethod."
logger.__noSuchMethod__ = function(name, args){
    this.log('Try another method, please.');
};
logger.newMethod('Test me again'); // output: "Try another method, please."

Special property: once

If needed, all the primitive console methods are accessible through the once object:

var logger = new OWM('l'); // Enabled log method only
logger.log(1); // output: 1
logger.warn(2); // no output
logger.once.warn(3); // output: 3
logger.warn(4); // no output

Examples

var levels = [ 'l', 'w', 'e', '-w', '-i-d-t' ];
var logger = new OWM(levels);
logger.log(1); // output: 1
logger.warn(2); // no output
logger.error(3); // output: 3
logger.info('No output'); // no output
logger.debug('No output'); // no output
logger.trace('No output'); // no output

levels = '-la'; // -l: disables log method, a: enables all (-l is ignored)
logger.options(levels);
logger.log(4); // output: 4
logger.warn(5); // output: 5
logger.error(6); // output: 6

logger.options('-a'); // disables all
logger.log(7); // no output
logger.warn(8); // no output
logger.error(9); // no output
logger.once.log(71); // output: 71
logger.once.warn(81); // output: 81
logger.once.error(91); // output: 91

logger.reset(); // alias for logger.option() with no parameter: all primitive console functionalities are recovered
logger.log(10); // output: 10
logger.warn(11); // output: 11
logger.error(12); // output: 12

var logger = new OWM('w,e'); // warn and error outputs only are enabled
logger.warn('This is a warning!');
logger.log('This log is ignored!'); // this outputs nothing
logger.error('This is an error!');

logger.reset(); // re-enable all the console functionalities
logger.options('a'); // alternative for logger.reset();
logger.options('l,e'); // enable output for console.log and console.error only

logger.warn('This warn is not shown.');
logger.options('w').warn('This new warn is shown');
logger.log('This log is not shown.');
logger.error('This error is not shown.');
logger.options('e').error('This error is visible.');