From f8745f2c89e3c71a35b573559627f54e2515bf62 Mon Sep 17 00:00:00 2001 From: d34thwings Date: Fri, 23 Aug 2019 12:13:04 +0000 Subject: [PATCH 1/3] Feat: Add support for console string fromat in browser --- src/reporters/browser.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/reporters/browser.js b/src/reporters/browser.js index c9ed0dc2..a2e31912 100644 --- a/src/reporters/browser.js +++ b/src/reporters/browser.js @@ -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}; @@ -38,10 +37,15 @@ export default class BrowserReporter { ` // Log to the console - consoleLogFn( - '%c' + [tag, type].filter(Boolean).join(':'), - style, - ...logObj.args - ) + if (typeof logObj.args[0] === 'string') { + consoleLogFn( + `%c${[tag, type].filter(Boolean).join(':')}%c ${logObj.args[0]}`, + style, + '', + ...logObj.args.slice(1) + ) + } else { + consoleLogFn(`%c${[tag, type].filter(Boolean).join(':')}`, style, ...logObj.args) + } } } From 38f727c2e0e9b870bab961684c8421781d9e5161 Mon Sep 17 00:00:00 2001 From: d34thwings Date: Fri, 23 Aug 2019 12:34:41 +0000 Subject: [PATCH 2/3] fix pr feedback --- src/reporters/browser.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/reporters/browser.js b/src/reporters/browser.js index a2e31912..6db818e7 100644 --- a/src/reporters/browser.js +++ b/src/reporters/browser.js @@ -36,16 +36,18 @@ export default class BrowserReporter { padding: 2px 0.5em; ` + const badge = `%c${[tag, type].filter(Boolean).join(':')}` + // Log to the console if (typeof logObj.args[0] === 'string') { consoleLogFn( - `%c${[tag, type].filter(Boolean).join(':')}%c ${logObj.args[0]}`, + `${badge}%c ${logObj.args[0]}`, style, '', ...logObj.args.slice(1) ) } else { - consoleLogFn(`%c${[tag, type].filter(Boolean).join(':')}`, style, ...logObj.args) + consoleLogFn(badge, style, ...logObj.args) } } } From 716d98832103e23915f7d28c86142656cf9b3c91 Mon Sep 17 00:00:00 2001 From: d34thwings Date: Mon, 26 Aug 2019 12:56:48 +0000 Subject: [PATCH 3/3] fix pr feedback 2 --- src/reporters/browser.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reporters/browser.js b/src/reporters/browser.js index 6db818e7..b07c311e 100644 --- a/src/reporters/browser.js +++ b/src/reporters/browser.js @@ -43,6 +43,7 @@ export default class BrowserReporter { consoleLogFn( `${badge}%c ${logObj.args[0]}`, style, + // Empty string as style resets to default console style '', ...logObj.args.slice(1) )