-
Notifications
You must be signed in to change notification settings - Fork 0
/
winston.js
31 lines (26 loc) · 973 Bytes
/
winston.js
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
const winston = require('winston')
const { path: rootPath } = require('app-root-path')
const {combine, timestamp, prettyPrint, colorize , printf} = winston.format
const generalFormat = combine(
timestamp({ format: 'YYYY/MM/DD HH:mm:ss' }),
printf(info => `[${info.timestamp}] ${info.service} ${info.level}: ${info.message}`)
)
const consoleFormat = combine(
colorize({ all: true }),
timestamp({ format: 'YYYY/MM/DD HH:mm:ss' }),
printf(info => `[${info.timestamp}] ${info.service} ${info.level}: ${info.message}`)
)
// winston.addColors()
const logger = winston.createLogger({
level: 'debug',
format: generalFormat,
defaultMeta: { service: 'events-listener' },
transports: [
new winston.transports.File({ filename: `${rootPath}/logs/error.log`, level: 'error' }),
new winston.transports.File({ filename: `${rootPath}/logs/events.log` }),
new winston.transports.Console({
format: consoleFormat
})
],
});
module.exports = logger