Skip to content

Instantly share code, notes, and snippets.

@gustinmi
Created February 13, 2013 16:41
Show Gist options
  • Save gustinmi/4945940 to your computer and use it in GitHub Desktop.
Save gustinmi/4945940 to your computer and use it in GitHub Desktop.
Simple JavaScript logging framework.
/**
* Simple logging framwork
* Supports Chrome or Firefox
* Usage:
*
* AppHtml5.log.info('Dropdown value changed to something new!');
*
*/
//create logging functions
(function () {
var assembleOutput = function (stuff, e) {
var lines = [ stuff ];
if (e && e.stack) lines.push(e.stack);
return lines.join('\n');
};
//for chrome
if (window.console && console.log) {
AppHtml5.log.debug = function (stuff, e) {
if (AppHtml5.settings.logEnabled) console.log(assembleOutput('DEBUG: ' + stuff, e));
};
AppHtml5.log.info = function (stuff, e) {
if (AppHtml5.settings.logEnabled) console.log(assembleOutput('INFO: ' + stuff, e));
};
AppHtml5.log.error = function (stuff, e) {
if (AppHtml5.settings.logEnabled) console.log(assembleOutput('ERROR: ' + stuff, e));
};
}
else { //for firefox
AppHtml5.log.debug = function (stuff, e) {
if (AppHtml5.settings.logEnabled) dump(assembleOutput('DEBUG: ' + stuff, e));
};
AppHtml5.log.info = function (stuff, e) {
if (AppHtml5.settings.logEnabled) dump(assembleOutput('INFO: ' + stuff, e));
};
AppHtml5.log.error = function (stuff, e) {
if (AppHtml5.settings.logEnabled) dump(assembleOutput('ERROR: ' + stuff, e));
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment