logger.js
1.39 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const {transports, createLogger, format} = require('winston');
require('winston-daily-rotate-file');
module.exports = (loggers) => {
const tps = loggers.map(log => {
switch (log.type) {
case 'console':
return new transports.Console(Object.assign({
level: 'info'
}, log));
case 'file':
return new transports.File(Object.assign({
level: 'info',
zippedArchive: true,
maxsize: 209715200, // 200m
maxFiles: 7,
}, log));
case 'dailyfile':
return new transports.DailyRotateFile(Object.assign({
level: 'info',
zippedArchive: true,
maxSize: '200m',
maxFiles: '7d',
datePattern: 'YYYY-MM-DD',
dirname: './logs'
}, log));
default:
return void 0;
}
});
const logger = createLogger({
level: 'info',
format: format.combine(
format.timestamp({
format: () => {
return new Date().toLocaleString();
}
}),
format.printf(info => `${info.level}: ${info.message}`)
),
transports: tps
});
return logger;
};
module.exports.logger = module.exports([{
silent: true,
type: 'dailyfile',
level: 'info',
filename: 'logs/info.log',
}, {
silent: true,
type: 'dailyfile',
level: 'error',
filename: 'logs/error.log',
}, {
type: 'console',
level: 'debug',
}]);