1 | export default class BrowserReporter {
|
2 | constructor (options) {
|
3 | this.options = Object.assign({}, options)
|
4 |
|
5 | this.defaultColor = '#7f8c8d'
|
6 | this.levelColorMap = {
|
7 | 0: '#c0392b',
|
8 | 1: '#f39c12',
|
9 | 3: '#00BCD4'
|
10 | }
|
11 | this.typeColorMap = {
|
12 | success: '#2ecc71'
|
13 | }
|
14 | }
|
15 |
|
16 | log (logObj) {
|
17 | const consoleLogFn = logObj.level < 1
|
18 |
|
19 | ? (console.__error || console.error)
|
20 |
|
21 | : logObj.level === 1 && console.warn ? (console.__warn || console.warn) : (console.__log || console.log)
|
22 |
|
23 |
|
24 | const type = logObj.type !== 'log' ? logObj.type : ''
|
25 |
|
26 |
|
27 | const tag = logObj.tag ? logObj.tag : ''
|
28 |
|
29 |
|
30 |
|
31 | const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor
|
32 | const style = `
|
33 | background: ${color};
|
34 | border-radius: 0.5em;
|
35 | color: white;
|
36 | font-weight: bold;
|
37 | padding: 2px 0.5em;
|
38 | `
|
39 |
|
40 |
|
41 | consoleLogFn(
|
42 | '%c' + [tag, type].filter(Boolean).join(':'),
|
43 | style,
|
44 | ...logObj.args
|
45 | )
|
46 | }
|
47 | }
|