1 | const chalk = require('chalk')
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | const generateLogMsg = (mark, type, content) => {
|
20 | if (typeof mark !== 'undefined' && typeof type === 'undefined' && typeof content === 'undefined')
|
21 | return generateLogMsg('', '', mark)
|
22 | if (typeof type !== 'undefined' && typeof content === 'undefined')
|
23 | return generateLogMsg(mark, '', type)
|
24 |
|
25 | let markColor = 'cyan'
|
26 | if (mark === false) mark = ''
|
27 | switch (mark.toLowerCase()) {
|
28 | case '×':
|
29 | case 'x':
|
30 | case 'x ':
|
31 | case 'error': {
|
32 | mark = '× '
|
33 | markColor = 'redBright'
|
34 | break
|
35 | }
|
36 | case 'success': {
|
37 | mark = '√ '
|
38 | markColor = 'green'
|
39 | break
|
40 | }
|
41 | case 'cb':
|
42 | case 'callback': {
|
43 | mark = '⚑ '
|
44 | markColor = 'cyan'
|
45 | break
|
46 | }
|
47 | case 'warning': {
|
48 | mark = '! '
|
49 | markColor = 'yellowBright'
|
50 | break
|
51 | }
|
52 | case '': {
|
53 | break
|
54 | }
|
55 | default: {
|
56 | mark = ' '
|
57 | }
|
58 | }
|
59 |
|
60 | const typeColor = (() => {
|
61 | switch (type) {
|
62 | default: return 'yellowBright'
|
63 | }
|
64 | })()
|
65 |
|
66 | return (mark === '' ? '' : chalk[markColor](mark))
|
67 | + chalk[typeColor](`[koot${type ? `/${type}` : ''}] `)
|
68 | + content
|
69 | }
|
70 |
|
71 | module.exports = generateLogMsg
|