Skip to content

Instantly share code, notes, and snippets.

@321hendrik
Last active August 19, 2016 13:02
Show Gist options
  • Save 321hendrik/e5a6efcda0a5d2807f46ab8676299726 to your computer and use it in GitHub Desktop.
Save 321hendrik/e5a6efcda0a5d2807f46ab8676299726 to your computer and use it in GitHub Desktop.
console.log without base64 images (or other long strings)
function logObjWithoutBase64 () {
function rmb64(o) {
if (typeof(o) == 'object') {
for (var k in o) {
o[k] = rmb64(o[k]);
}
} else if (typeof(o) == 'string' && o.length > 100) {
return 'BASE64';
}
return o;
}
var l = [];
for (var a in arguments) {
if (typeof(arguments[a]) == 'object'){
l.push(rmb64(JSON.parse(JSON.stringify(arguments[a]))));
} else {
l.push(arguments[a]);
}
}
console.log.apply(this, l);
// // alternatively you can use the one below (for frameworks that do no support console.log.apply)
// console.log(l.map(function(e) {return JSON.stringify(e, null, 4);}).join(' '));
}
console.nice = logObjWithoutBase64;
// call it: console.nice('my comment', someObjectWithBase64Properties);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment