Skip to content

Instantly share code, notes, and snippets.

@brandonpapworth
Created February 12, 2014 10:20
Show Gist options
  • Save brandonpapworth/8952971 to your computer and use it in GitHub Desktop.
Save brandonpapworth/8952971 to your computer and use it in GitHub Desktop.
Iron-clad console logging alternative. Use like " logger('log', /* all your arguments you'd normally pass */); "
/**
* shims in console support and ignores calls if console
* object is not present in window
* @param {String} kind the kind of logging statement to make
* @param {Any} argX (optional) the remainder of the logging arguments
* @return {Object} returns App
*/
function logger (kind /*[,arg1, arg2, ..., argN]*/) {
try {
if (typeof kind === 'string' && window.console && typeof window.console[kind] === 'function' && typeof Array.prototype.slice === 'function') {
window.console[kind].apply(window.console,Array.prototype.slice.call(arguments,1));
}
} catch (e) {
if (window.console && window.console.error) {
window.console.error('ERROR',e);
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment