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

magiconsole

v0.2.2

Published

Lightweight namespaced console for easy enabling and disabling of console messages in your project.

Downloads

324

Readme

NPM version Dependency Status Build Status Code Climate Code Climate Coverage

MagiConsole

A magical namespaced console wrapper with loglevel support for node.js and the browser.

Usage

Require or include MagiConsole and create some namespaced console objects:

Node

var MagiConsole = require('magiconsole');

Browser

<script TYPE="text/javascript" src="MagiConsole.min.js"></script>

Once the script is loaded, MagiConsole is available on window. You can also require MagiConsole.js with your favorite AMD loader.

var ioConsole = new MagiConsole('IO');
var dbConsole = new MagiConsole('DB');

The MagiConsole constructor caches namespaced instances. You can require and create namespaced consoles throughout your project, but only one object instance will be created per namespace.

Namespaces

By default nothing is output from magiconsole:

ioConsole.info('web socket connected');
dbConsole.info('useing indexeddb');

(nothing is output to the console)

Enable MagiConsole namespaces with regex patterns:

// setup namespace regex pattern:
MagiConsole.setPattern('IO');

ioConsole.error('socket error');
dbConsole.warn('table not found');
> [IO] socket error

Enable all namespaces with a special wildcard string:

MagiConsole.setPattern('*');

ioConsole.debug('200 OK');
dbConsole.log('all data loaded');
> [IO] 200 OK
> [DB] all data loaded

Enable namespaces via environment variables:

> MLOG=foo node fooAndBarLogs.js

MagiConsole.setPattern

Sets the current regex pattern namespaces are tested against.

MagiConsole.setPattern('network|db') will allow all namespaces containing 'network' or 'db'.

MagiConsole.setPattern('^file') will allow all namespaces starting with 'file'.

MagiConsole.setPattern('^(?!io).+') will allow all namespaces that do not start with 'io'.

Log Levels

MagiConsole wraps all methods normally available via console in modern browsers and ensures that the leveled methods error, warn, log, info and debug are always available both in the browser and node.

By default no log level is set and all methods are enabled to write to the console.

Set a log level and allow only messages of the same or greater severity:

var onlyThisLevel = false;
MagiConsole.setLevel('warn', onlyThisLevel);
MagiConsole.setPattern('*');

ioConsole.warn('a warning');
dbConsole.error('an error');
ioConsole.debug('a boring debug message');
> [IO] a warning
> [DB] an error

Whitelist a loglevel:

var onlyThisLevel = true;
MagiConsole.setLevel('warn', onlyThisLevel);
MagiConsole.setPattern('*');

ioConsole.log('connected to foo.b.ar');
dbConsole.warn('write not completed within 100ms');
> [IO] connected to foo.b.ar

Reenable all console methods:

MagiConsole.setLevel('*');
MagiConsole.setPattern('*');

ioConsole.log('connecting ...');
dbConsole.warn('store not found');
> [IO] connecting ...
> [DB] store not found

Set log level via environment variable:

> MLEVEL=info node allSortsOfMagiConsoleMethods.js

Reset

Reset MagiConsole to the default state of not logging anything:

MagiConsole.reset();

Environment Variables

MagiConsole can be configured via the command line using environment variables:

  • MLOG sets the namespace regex pattern

  • MLEVEL sets the loglevel

  • MLEVELONLY set to only allow the loglevel and no other severities

Develop and contribute

You need to have node and npm installed. Then fork this repo and open it in your terminal.

Install dependencies

$ make install

Run tests

$ make test

Run tests and watch for changes

$ make start

Generate coverage report

$ make coverage

Run JSLint

$ make lint

Build for distribution

$ make build

Resources