Skip to content

Instantly share code, notes, and snippets.

@nurbek-ab
Last active October 21, 2016 13:19
Show Gist options
  • Save nurbek-ab/1bfbdb16947a2e8fa7969994811c744b to your computer and use it in GitHub Desktop.
Save nurbek-ab/1bfbdb16947a2e8fa7969994811c744b to your computer and use it in GitHub Desktop.
Logs prettyfied and colored objects to console
var util = require('util');
var _ = require('lodash');
/**
* Logs prettyfied and colored objects to console
* @param msg - message
* @param title - log message title
* @param depth - property depth
* @param showHidden - show hidden properties
*/
export function inspect(msg, title, depth, showHidden) {
title = title || 'inspecting';
if(_.isObject(msg) || _.isArray(msg)) {
var res = util.inspect(msg, {
depth: depth || 10,
colors: true,
showHidden: showHidden || false
});
console.log('');
console.log('\x1b[36m', '---------------------------| ' + title + ' |---------------------------', '\x1b[0m');
console.log(res);
console.log('\x1b[36m', '-----------------------------------------------------------------------', '\x1b[0m');
console.log('');
} else {
console.log('');
console.log('\x1b[36m', '---------------------------| ' + title + ' |---------------------------', '\x1b[0m');
console.log('\x1b[33m', msg, '\x1b[0m');
console.log('\x1b[36m', '-----------------------------------------------------------------------', '\x1b[0m');
console.log('');
}
}
export default {inspect};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment