-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.ts
52 lines (43 loc) · 997 Bytes
/
logger.ts
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import winston, { addColors, format } from 'winston'
const levels = {
error: 0,
warn: 1,
info: 2,
http: 3,
debug: 4
}
const level = () => {
const env = process.env.NODE_ENV || 'dev'
const isDev = env === 'dev'
return isDev ? 'debug' : 'warn'
}
const colors = {
error: 'red',
warn: 'yellow',
info: 'green',
http: 'magenta',
debug: 'white'
}
addColors(colors)
const nformat = format.combine(
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss:ms' }),
format.colorize({ all: true }),
format.printf(
(info) => `${info.timestamp} ${info.level} ${info.message}`
)
)
const transports = [
new winston.transports.Console(),
new winston.transports.File({
filename: 'logs/error.log',
level: 'error'
}),
new winston.transports.File({ filename: 'logs/all.log' })
]
const Logger = winston.createLogger({
level: level(),
levels,
format: nformat,
transports
})
export default Logger