SutisLogSummary.js
2.06 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
63
64
65
66
67
68
69
70
71
72
73
74
75
var log4js = require('log4js');
log4js.configure('./config/log4js.json');
var log = log4js.getLogger('serverLog');
var stat = log4js.getLogger('statLog');
var alarm = log4js.getLogger('alarmLog');
var detail = log4js.getLogger('datailLog');
var summary = log4js.getLogger('summaryLog');
var dateFMT = 'yyyymmdd HH:MM:ss';
var dateFormat = require('dateformat');
var l = {};
l.debug = function(_log){
log.debug(_log);
}
l.info = function(_log){
log.info(_log);
}
l.warn = function(_log){
log.warn(_log);
}
l.error = function(_log){
log.error(_log);
}
l.stat = function(statName){
stat.info(statName);
}
l.alarm = function(alarmName){
alarm.info(alarmName);
}
l.detail = function(appDetail){
detail.info(appDetail);
}
l.summary = function(session, cmd, identity, resultCode, resultDescription){
var summaryLog = {
requestTime: new Date(),
session: session,
initInvoke: '', //only equinox platform
cmd: cmd,
identity: identity,
resultCode: resultCode,
resultDescription: resultDescription,
blockDetail: [],
addSuccessBlock: function(node, cmd, statusCode, detail){
this.blockDetail.push('['+ node+'; '+cmd+'(1); ['+ statusCode+'; '+detail+'(1)]]');
},
addErrorBlock: function(node, cmd, statusCode, detail, errorDetail){
this.blockDetail.push('['+ node+'; '+cmd+'(1); ['+ statusCode+'; '+detail+'(1)]]');
},
flush : function(){
var endTime = new Date();
var txt = dateFormat(this.requestTime, dateFMT) + '|';
txt += this.session +'|';
txt += this.initInvoke +'|'
txt += this.cmd +'|'
txt += this.identity +'|'
txt += this.resultCode +'|'
txt += this.resultDescription +'|'
txt += this.blockDetail +'|'
txt += dateFormat(endTime, dateFMT) +'|'
txt += (endTime.getTime() - this.requestTime.getTime());
summary.info(txt);
}
};
return summaryLog;
}
module.exports = l;