Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Super-simple, client-side CommonJS logging thingy
JavaScript
Branch: master

This branch is 17 commits behind HenrikJoreteg:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
&log.js
readme.md
test.html

readme.md

&log

Super simple, but solves these pain points:

  • Lets you leave log statements in production, client-side code.
  • It won't log anything unless localStorage.debug is set.
  • Uses native console rather than trying to wrap it in something (which makes the output ugly).
  • Works with CommonJS.
  • It's just a selective alias for the window.console so the normal API applies.

How to use it:

Step 1. include it:

<script src="&log.js"></script>

Step 2. Use the console in your code as usual:

console.log("hello");

Step 3. If you want to see log output set a value called debug in localStorage by doing typing this in console:

localStorage.debug = true

Step 4. Refresh the page, you should now see logs.

Step 5. To turn off console, just delete the localStorage flag:

delete localStorage.debug

Step 6. Feel free to deploy to production with console stuff in there.

CommonJS Version

var logger = require('&log');

logger.log('hello');

This is identical to:

console.log('hello');

You could even get fancy and call it console. However by doing this you take the risk that you'll forget to require it and it'll still work and you'll ship it to production. However, obviously this would work as well:

var console = require('&log');

console.log('hello');

License

MIT

Something went wrong with that request. Please try again.