Last active
October 21, 2016 13:19
-
-
Save nurbek-ab/1bfbdb16947a2e8fa7969994811c744b to your computer and use it in GitHub Desktop.
Logs prettyfied and colored objects to console
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
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