-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.js
More file actions
54 lines (44 loc) · 1.31 KB
/
logger.js
File metadata and controls
54 lines (44 loc) · 1.31 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
var winston = require('winston');
var moment = require('moment');
var dateFormat=function() {
return moment().format('YYYY-MM-DD HH:mm:ss:SSS');
};
// winston.remove(winston.transports.Console);
// winston.add(winston.transports.Console, {'timestamp':function(){
// return dateFormat();
// },'colorize':true});
//winston.info("test");
var date = new Date();
var file_name = date.getFullYear() + '_' + (date.getMonth() + 1) + '_' +date.getDate();
var logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({'timestamp': function(){
return dateFormat();
}}),
new (winston.transports.File)({
filename: 'logs/'+ file_name +'.log',
timestamp:dateFormat,
colorize:true,
maxsize:1024*1024*10
})
]
});
var crashLogger= new (winston.Logger)({
transports: [
new (winston.transports.File)({
name: 'error',
filename: '/logs/crash.log',
level: 'error',
handleExceptions: true,
timestamp:dateFormat,
humanReadableUnhandledException: true,
json: false,
colorize:true,
maxsize:1024*1024*10
})
]
});
//use
//logger.log('info', 'Hello distributed log files!');
// logger.info('Hello again distributed logs');
module.exports = logger;