-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.ts
More file actions
36 lines (35 loc) · 1 KB
/
Copy pathconsole.ts
File metadata and controls
36 lines (35 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import consoleStamp from 'console-stamp'
import chalk from 'chalk'
export function initializeConsole() {
consoleStamp(console, {
format: ':date(yyyy-mm-dd HH:MM:ss.l).yellow.bgBlue :level() :msg',
include: ['log', 'info', 'warn', 'error', 'debug'],
level: 'debug',
tokens: {
level: (opts) => {
// opts.method is the log level (e.g., 'info', 'warn', etc.)
const level = opts.method
let colorFn = (s: string) => s // default: no color
switch (level) {
case 'info':
colorFn = chalk.cyan
break
case 'debug':
colorFn = chalk.gray
break
case 'warn':
colorFn = chalk.yellow
break
case 'error':
colorFn = chalk.red
break
default:
colorFn = chalk.white
}
// Default label format: [LEVEL]
const label = `[${level.toUpperCase()}]`.padEnd(7, ' ')
return colorFn(label)
},
},
})
}