Created
November 12, 2010 01:11
-
-
Save bunnymatic/673560 to your computer and use it in GitHub Desktop.
Provide a tiny module that will allow for safe logging to console for browsers that allow it. For those that don't, don't log anything. Easily turned off with a debug switch which can be server generated (depending on environment dev/staging/prod) or no
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
var L = window.SafeLogger = window.SafeLogger || {}; | |
// | |
// from server or on a specific page you want console data | |
// L.__debug__ = true | |
// | |
L.log = function() { | |
if (window.console && L.__debug__) { | |
// TODO: Chrome doesn't let us call apply on console.log. | |
// Interpolate variable arguments manually and construct | |
// a single-argument call to console.log for Chrome. | |
try { | |
console.log.apply(this, arguments); | |
} catch(e) { | |
try { | |
var i = 0; | |
var n = arguments.length; | |
for (;i<n;++i) { console.log(arguments[i]); } | |
} catch(ee) { | |
L.log = function() {}; | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment