Skip to content

Instantly share code, notes, and snippets.

@ferronrsmith
Created September 17, 2014 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferronrsmith/ceccd35cca6dbfe3cd20 to your computer and use it in GitHub Desktop.
Save ferronrsmith/ceccd35cca6dbfe3cd20 to your computer and use it in GitHub Desktop.
node-logging prettyPrintObj.js
// https://github.com/Monwara/node-logging/blob/master/logging.js
function prettyPrintObj(o, excludes) {
excludes = typeof excludes === 'undefined' ? EXCLUDES : excludes;
if (!o || typeof o !== 'object' || !Object.keys(o).length) {
return '*'.grey + ' ' + 'n/a'.green + '\n';
}
var rows = [];
Object.keys(o).forEach(function(key) {
var value;
if (excludes.length && excludes.indexOf(key) < 0) {
if (o[key] === null) {
value = 'null'.grey;
} else if (typeof o[key] === 'undefined') {
value = 'undefined'.grey;
} else {
value = o[key].toString();
}
} else {
value = '(excluded)'.grey;
}
rows.push('*'.grey + ' ' + key.green + ': ' + value);
});
return rows.join('\n') + '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment