Skip to content

Instantly share code, notes, and snippets.

@bunnymatic
Created November 12, 2010 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bunnymatic/673560 to your computer and use it in GitHub Desktop.
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
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