Code Monkey home page Code Monkey logo

andlog's Introduction

&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

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: https://github.com/henrikjoreteg/clientmodules and npm.

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

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

andlog's People

Contributors

henrikjoreteg avatar irae avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.