FormidableLabs/simple-console

Name: simple-console

Owner: Formidable

Description: A small, cross-browser-friendly console wrapper.

Created: 2015-02-27 16:56:12.0

Updated: 2017-09-19 13:24:51.0

Pushed: 2015-04-04 14:02:45.0

Homepage: null

Size: 320

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Simple Console

Provides a simple, but useful cross-browser-compatible console logger.

Build Status Coverage Status

Sauce Test Status

Features
Installation

Install via npm:

m install simple-console

or bower:

wer install simple-console
Usage

Import the SimpleConsole class into your code (via AMD, CommonJS, etc) and use as a drop-in replacement for console.OPERATION. Creating a new object does not effect the existing window.console object.

AMD
ne(["simple-console"], function (SimpleConsole) {
r con = new SimpleConsole();
n.log("Hello world!");

CommonJS
SimpleConsole = require("simple-console");
con = new SimpleConsole();
log("Hello world!");
VanillaJS

In your HTML:

 Option One: Minified -->
ipt src="PATH/TO/simple-console/dist/simple-console.min.js"></script>

 Option Two: Raw source -->
ipt src="PATH/TO/simple-console/simple-console.js"></script>

In your JS:

con = new window.SimpleConsole();
log("Hello world!");
Noop Logger

There are some cases where you will want to conditionally silence the logger. You can do this by passing setting the noop option:

con = new SimpleConsole({ noop: true });
log("Hello world!"); // => Should _not_ output anything.

This is usually useful in a case where you build different capabilities based on some external information, for example, React-style, this could be something like:

con = new SimpleConsole({
op: process.env.NODE_ENV === "production"


log("Hello world!"); // => Should _not_ output anything in `production`.
Polyfill

If you are looking to polyfill console, then you can:

SimpleConsole({ patch: true });

This will mutate the window.console object in ways that are not easily undone, so consider this a “one way” patch. Moreover, if window.console does not exist, it will create the object.

You can even go further and patch and noop the logger with:

SimpleConsole({ patch: true, noop: true });

which ensures that nothing logs anything.

Note: In addition to filling/patching missing behavior, the polyfill will replace behavior that already exists and works. This is presently due to complexities likely normalizing and ensuring things like .bind, .apply and .call work on all log methods.

Development

Run checks, then development server:

lp

Separated:

lp check
lp dev

Execute the demo code:

de examples/demo.js
antomjs examples/demo.js

Navigations:

Release process:

Also See

Similar projects that can help with console:

License

Copyright 2015 Formidable Labs, Inc. Released under the MIT License,


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.