Created
February 13, 2013 16:41
-
-
Save gustinmi/4945940 to your computer and use it in GitHub Desktop.
Simple JavaScript logging framework.
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
/** | |
* 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