UNPKG

501 BJavaScriptView Raw
1const chalk = require('chalk')
2
3const type2Color = {
4 info: 'green',
5 error: 'red',
6 webpack: 'yellow',
7 node: 'cyan',
8 route: 'blue',
9 proxy: 'gray',
10 consume: 'gray'
11}
12
13const maxLen = Math.max(...Object.keys(type2Color).map(v => v.length))
14
15const logger = Object.entries(type2Color).reduce((prev, [type, color]) => {
16 prev[type] = str => {
17 console.log(
18 chalk[color](type),
19 `${' '.repeat(maxLen - type.length)} ${str}`
20 )
21 }
22
23 return prev
24}, {})
25
26module.exports = logger