Skip to content

Commit

Permalink
feat(browser): add support of formatted strings (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
D34THWINGS authored and pi0 committed Sep 1, 2019
1 parent ac7c38a commit 920f313
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/reporters/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default class BrowserReporter {
const tag = logObj.tag ? logObj.tag : ''

// Styles

const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor
const style = `
background: ${color};
Expand All @@ -37,11 +36,19 @@ export default class BrowserReporter {
padding: 2px 0.5em;
`

const badge = `%c${[tag, type].filter(Boolean).join(':')}`

// Log to the console
consoleLogFn(
'%c' + [tag, type].filter(Boolean).join(':'),
style,
...logObj.args
)
if (typeof logObj.args[0] === 'string') {
consoleLogFn(
`${badge}%c ${logObj.args[0]}`,
style,
// Empty string as style resets to default console style
'',
...logObj.args.slice(1)
)
} else {
consoleLogFn(badge, style, ...logObj.args)
}
}
}

0 comments on commit 920f313

Please sign in to comment.