Skip to content

Commit

Permalink
feat(fancy/basic): support logObj.stack field
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 5, 2018
1 parent 2d4af39 commit aa2216f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Shortcut to `withDefaults({ scope })`.

- `level`

The level to display logs. Any logs at or above this level will be displayed.
The level to display logs. Any logs at or above this level will be displayed.
List of available levels [here](./src/types.js)

## logObject
Expand All @@ -158,6 +158,7 @@ Extended fields:
- `clear`
- `badge`
- `additional`
- `stack`
- `additionalStyle` (By default: `grey`)
- `icon` (Default depends on log type)

Expand Down
4 changes: 4 additions & 0 deletions src/reporters/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ export default class BasicReporter {
if (logObj.additional) {
this.stream.write(logObj.additional + '\n')
}

if (logObj.stack) {
this.stream.write(logObj.stack + '\n')
}
}
}
6 changes: 6 additions & 0 deletions src/reporters/fancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@ export default class FancyReporter {
const lines = logObj.additional.split('\n').map(s => ' ' + s).join('\n')
this.stream.write(chalk[logObj.additionalStyle || 'grey'](lines) + '\n')
}

if (logObj.stack) {
const stack = Array.isArray(logObj.stack) ? logObj.stack : logObj.stack.split('\n')
const lines = stack.map(s => ' ' + s.trim()).join('\n')
this.stream.write(chalk[logObj.additionalStyle || 'grey'](lines) + '\n')
}
}
}

0 comments on commit aa2216f

Please sign in to comment.