Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created April 26, 2012 09:28
Show Gist options
  • Save pamelafox/2498072 to your computer and use it in GitHub Desktop.
Save pamelafox/2498072 to your computer and use it in GitHub Desktop.
ED.util.log()
// 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