Created
April 26, 2012 09:28
-
-
Save pamelafox/2498072 to your computer and use it in GitHub Desktop.
ED.util.log()
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
// Logging | |
var allLogs = []; | |
function log(something) { | |
// Store | |
var storedSomething = something; | |
if (window.JSON) { | |
storedSomething = JSON.stringify(something); | |
} | |
storedSomething = 'LOG @ ' + new Date().toString() + ': ' + truncateText(storedSomething, 200); | |
allLogs.push(storedSomething); | |
$('#mobile-feedback-logs').html(allLogs.reverse().join('<br>')); | |
// Output | |
if (window.console) { | |
if (something instanceof Date) { | |
something = something.toDateString(); | |
} | |
if (isIOS() || isAndroid()) { | |
if (typeof something == 'object') { | |
something = JSON.stringify(something); | |
} | |
something = truncateText(something, 2000); | |
something = '\nLOG: ' + something; | |
var stacktrace = ''; | |
if (window.printStackTrace) { | |
try { | |
stacktrace = '\n -' + printStackTrace().slice(4).join('\n -'); | |
something += '\nSTACKTRACE:' + stacktrace; | |
} catch(e) {} | |
} | |
if (isIOS()) { | |
//alert(something); | |
console.log(something); | |
} else { | |
console.log(something); | |
} | |
if ($('#logs-viewer').length) { | |
$('#logs-viewer').prepend(something.replace(/\n/g, '<br>') + '<br>'); | |
} | |
} else { | |
console.log(something); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment