Skip to content

Instantly share code, notes, and snippets.

@js2me
Last active October 31, 2018 20:10
Show Gist options
  • Save js2me/0cbcece8eab2e8c78b3ddee8c28cc561 to your computer and use it in GitHub Desktop.
Save js2me/0cbcece8eab2e8c78b3ddee8c28cc561 to your computer and use it in GitHub Desktop.
Better object log using console in web
console.logObject = function(...args) {
const log = args.reduce((logs, object, index) => {
if (typeof object === 'object' && !(object instanceof Array)) {
logs.push(`\r\n{ `)
logs.push.apply(
logs,
Object.keys(object).reduce((values, key) => {
values.push(
`\r\n ${key}:`,
typeof object[key] === 'function' ? '[function]' : object[key],
', '
)
return values
}, [])
)
logs.push('\r\n}')
} else logs.push('\r\n', object)
return logs
}, [])
this.group.call(this, ...log) //eslint-disable-line
this.groupCollapsed('call stack ->')
this.log.call(this, ...Error().stack.split(/\n/).slice(2).map(log => log + '\n')) //eslint-disable-line
this.groupEnd()
this.groupEnd()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment