Created
February 12, 2014 10:20
-
-
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 */); "
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
/** | |
* 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