Skip to content

Commit

Permalink
feat: support extra log arguments
Browse files Browse the repository at this point in the history
Align behaviour with original console.log
  • Loading branch information
Pooya Parsa committed Apr 15, 2018
1 parent efeab44 commit 8b6d3d2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ consola.start('Starting build')

consola.warn('Something is going to happen soon')

consola.log('Bla', 'Bla', 'Bla', 'Bla')

setTimeout(() => {
consola.success('Build succeed in 10 seconds')
consola.info('Some extra info is here')
Expand Down
7 changes: 5 additions & 2 deletions src/consola.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class Consola {
}

_createLogFn (defaults) {
return opts => {
return (opts, ...args) => {
if (!opts) {
return this
}
Expand All @@ -27,14 +27,17 @@ export default class Consola {
date: new Date()
}, defaults)

const argsStr = Array.from(args).map(String).join(' ')

if (typeof opts === 'string') {
// String
logObj.message = opts
logObj.additional = argsStr
} else if (opts.stack) {
// Error
const [message, ...stack] = opts.stack.split('\n')
logObj.message = message
logObj.additional = stack.map(s => s.trim()).join('\n')
logObj.additional = (argsStr.length ? argsStr + '\n' : '') + stack.map(s => s.trim()).join('\n')
} else {
// Object
Object.assign(logObj, opts)
Expand Down

0 comments on commit 8b6d3d2

Please sign in to comment.