andlog
Super-simple, client-side CommonJS logging thingy
Last updated a year ago by henrikjoreteg .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install andlog 
SYNC missed versions from official npm registry.

&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="andlog.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

If you'd like to use a custom debug key then set localStorage.andlogKey = 'something-else' and then set localStorage['something-else'] = true to enable logging.

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

If you're using this on the client but your project is in node.js you can install this with: browserify and npm.

var logger = require('andlog');

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('andlog');

console.log('hello');

Releases

  • 1.0.2 bug fix to make sure ls is always defined.

License

MIT

If you like this, follow @HenrikJoreteg on the twitterwebz.

Current Tags

  • 1.0.2                                ...           latest (a year ago)

6 Versions

  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.4                                ...           7 years ago
  • 0.0.3                                ...           8 years ago
  • 0.0.2                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 16
Dependencies (0)
None
Dev Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |