Last active
December 9, 2015 23:28
-
-
Save impressiver/4343889 to your computer and use it in GitHub Desktop.
Was thinking that it would be nice to leave console messages in the front end code, with a switch to turn them on and off, making quick production debug sessions hassle-free. So I made a light `window.console` wrapper that routes `console` calls to noop functions if debug is not enabled, but back to the original console if you have `DEBUG = true…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! | |
* Console Lite | |
* https://gist.github.com/impressiver/4343889 | |
* | |
* Stop wayward debug messages from inadvertently jamming up browsers. | |
* Setting `localStorage.DEBUG = true` will turn console messages on | |
* again, though you still only get partial console functionality | |
* (which is intentional). | |
* | |
* Copyright 2013 Impressiver LLC | |
* Released under the MIT license | |
* http://opensource.org/licenses/MIT | |
* | |
*/ | |
window.console = (function(w) { | |
"use strict"; | |
var wC = w.console, rC = {}, lS = w.localStorage, | |
fs = ["log", "error", "warn", "info", "debug", "dir", "trace", "time", "timeEnd"], | |
isD = function() { return (!!(lS && lS.DEBUG)); }, noop = function(){}, i; | |
for (i in fs) { | |
rC[fs[i]] = (!!wC && isD()) ? wC[fs[i]].bind(wC) : noop; | |
} | |
return rC; | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@toekneestuck: Good call - rookie mistake :) I'll update the gist to reflect your changes.