@@ -4,17 +4,43 @@ export default class BrowserReporter {
4
4
}
5
5
6
6
log ( logObj ) {
7
+ /*
8
+ * Symbol width is dependent on user's system font
9
+ *
10
+ * In Chrome:
11
+ * - console.error, warn and trace have collapsable output
12
+ * - trace is expanded by default
13
+ *
14
+ * In Firefox:
15
+ * - console.error has collapsable output
16
+ * - console.warn has not
17
+ * - console.trace is always expanded and has no style support
18
+ *
19
+ * In IE:
20
+ * - ?
21
+ */
7
22
const replaceColors = {
8
23
undefined : 'grey' ,
9
24
yellow : 'goldenrod' ,
10
25
white : 'grey'
11
26
}
27
+
28
+ //
29
+ const symbols = {
30
+ start : '\u25cf' ,
31
+ info : '\u2139' ,
32
+ success : '\u2713' ,
33
+ debug : '\u2026' ,
34
+ log : '\u276f' ,
35
+ ready : '\u2764'
36
+ // warn: '\u00a0' // non-breaking space to help alignment in FF
37
+ }
12
38
const color = replaceColors [ logObj . color ] ? replaceColors [ logObj . color ] : logObj . color
13
39
14
- const styleDefault = 'color: silver; background-color: inherit;'
40
+ const styleDefault = 'color: ' + color + '; background-color: inherit;'
41
+ const styleDiscrete = 'color: silver; background-color: inherit;'
15
42
const styleAdditional = 'color: ' + ( logObj . additionalColor ? logObj . additionalColor : 'black' ) + '; background-color: inherit;'
16
43
const badgeStyle = 'color: white; background-color: ' + color + ';'
17
- const style = 'color: ' + color + '; background-color: inherit;'
18
44
19
45
let type = logObj . type
20
46
if ( ! console [ type ] ) { // eslint-disable-line no-console
@@ -45,7 +71,12 @@ export default class BrowserReporter {
45
71
'%c' + ( logObj . args . length ? '\n' + logObj . args . join ( ) : '' )
46
72
]
47
73
48
- /* eslint-disable-next-line no-console */
49
- console [ type ] ( args . join ( ' ' ) , badgeStyle , styleDefault , style , styleAdditional )
74
+ if ( symbols [ logObj . type ] ) {
75
+ args . unshift ( '%c' + symbols [ logObj . type ] )
76
+ console [ type ] ( args . join ( ' ' ) , styleDefault , badgeStyle , styleDiscrete , styleDefault , styleAdditional )
77
+ } else {
78
+ /* eslint-disable-next-line no-console */
79
+ console [ type ] ( args . join ( ' ' ) , badgeStyle , styleDiscrete , styleDefault , styleAdditional )
80
+ }
50
81
}
51
82
}
0 commit comments