logger.js
1.11 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
var strftime = require('strftime');
var winston = require('winston');
var loggerTimestamp = function() {
return strftime('%F %T', new Date());
}
function start() {
var logger = new winston.Logger({
transports: [
new (winston.transports.Console)({
timestamp: function() {
return strftime('%F %T', new Date());
},
level: 'verbose',
}),
new (winston.transports.DailyRotateFile) ({
name: 'log-file-txt',
filename: 'logs/log.txt',
timestamp: loggerTimestamp,
formatter: function(options) {
return options.timestamp()
+' ' + options.level.toUpperCase()
+' ' + (undefined !== options.message ? options.message : '')
+ (options.meta && Object.keys(options.meta).length ? '\n\t' + JSON.stringify(options.meta) : '' );
},
level: 'debug',
}),
]
});
return logger;
}
exports.start = start;