-
Notifications
You must be signed in to change notification settings - Fork 0
/
laputa-log-conf.js
49 lines (45 loc) · 1.53 KB
/
laputa-log-conf.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const {createLogger, format, transports} = require('winston')
const {timestamp, label, printf} = format
const DailyRotateFile = require('winston-daily-rotate-file')
const fs = require('fs')
const path = require('path')
const pid = process.pid
const pname = path.basename(process.cwd())
const os = require('os')
const errorFormat = format((info, opts) => {
if (info instanceof Error) {
info.message = info.stack
}
if (info.error && info.error instanceof Error) {
info.message += os.EOL + info.error.stack
}
return info
})
module.exports = {
createLogger: () => {
return createLogger({
level: 'info',
format: format.combine(errorFormat(), format.timestamp(), format.printf((info) => {
return `[${info.timestamp}] [${info.level}] - ${info.message}`
})),
transports: [
new transports.Console(),
new DailyRotateFile({
level: 'error',
filename: `../logs/${pname}/error.%DATE%.log`,
datePattern: 'YYYY-MM-DD',
zippedArchive: false,
maxSize: '1000m',
maxFiles: '3d'
}),
new DailyRotateFile({
filename: `../logs/${pname}/service.%DATE%.log`,
datePattern: 'YYYY-MM-DD',
zippedArchive: false,
maxSize: '1000m',
maxFiles: '3d'
})
]
})
}
}