whatap 0.4.49 → 0.4.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/conf/config-default.js +28 -1
- package/lib/core/agent.js +7 -1
- package/lib/logger.js +300 -300
- package/lib/observers/http-observer.js +24 -5
- package/lib/requestlog.js +327 -0
- package/lib/trace/trace-context.js +3 -2
- package/lib/util/resourceprofile.js +1 -0
- package/package.json +2 -2
|
@@ -190,7 +190,34 @@ var ConfigDefault = {
|
|
|
190
190
|
"mtid_mtrace_enabled": bool('mtid_mtrace_enabled' , false),
|
|
191
191
|
|
|
192
192
|
// debug add
|
|
193
|
-
"network_debug_enabled" : bool('network_debug_enabled', false)
|
|
193
|
+
"network_debug_enabled" : bool('network_debug_enabled', false),
|
|
194
|
+
// reqlog add
|
|
195
|
+
"reqlog_rotation_enabled": true,
|
|
196
|
+
"reqlog_keep_days": 7,
|
|
197
|
+
"reqlog_enabled": false,
|
|
198
|
+
"reqlog_seperator" : str('reqlog_seperator', '|'),
|
|
199
|
+
|
|
200
|
+
"reqlog_x_etime" : bool('reqlog_x_etime', true),
|
|
201
|
+
"reqlog_x_elapsed" : bool('reqlog_x_elapsed', true),
|
|
202
|
+
"reqlog_x_url" : bool('reqlog_x_url', true),
|
|
203
|
+
"reqlog_x_httphost" : bool('reqlog_x_httphost', true),
|
|
204
|
+
"reqlog_x_method" : bool('reqlog_x_method', true),
|
|
205
|
+
"reqlog_x_ip" : bool('reqlog_x_ip', true),
|
|
206
|
+
"reqlog_x_wcid" : bool('reqlog_x_wcid', true),
|
|
207
|
+
"reqlog_x_status" : bool('reqlog_x_status', true),
|
|
208
|
+
"reqlog_x_error" : bool('reqlog_x_error', true),
|
|
209
|
+
"reqlog_x_errormsg" : bool('reqlog_x_errormsg', true),
|
|
210
|
+
"reqlog_x_useragent" : bool('reqlog_x_useragent', true),
|
|
211
|
+
"reqlog_x_txid" : bool('reqlog_x_txid', true),
|
|
212
|
+
"reqlog_x_custid" : bool('reqlog_x_custid', false),
|
|
213
|
+
"reqlog_x_gtid" : bool('reqlog_x_gtid', true),
|
|
214
|
+
"reqlog_x_mtid" : bool('reqlog_x_mtid', true),
|
|
215
|
+
"reqlog_x_mdepth" : bool('reqlog_x_mdepth', true),
|
|
216
|
+
"reqlog_x_httpc" : bool('reqlog_x_httpc', true),
|
|
217
|
+
"reqlog_x_sql" : bool('reqlog_x_sql', true),
|
|
218
|
+
"reqlog_x_dbc" : bool('reqlog_x_dbc', true),
|
|
219
|
+
"reqlog_x_login" : bool('reqlog_x_login', true),
|
|
220
|
+
"reqlog_x_rs" : bool('reqlog_x_rs', true),
|
|
194
221
|
};
|
|
195
222
|
|
|
196
223
|
ConfigDefault._hook_method_ignore_prefix = ConfigDefault.hook_method_ignore_prefixes.split(',');
|
package/lib/core/agent.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
var os = require('os'),
|
|
8
8
|
fs = require('fs'),
|
|
9
9
|
path = require('path');
|
|
10
|
+
const RequestLog = require('../requestlog');
|
|
10
11
|
|
|
11
12
|
var Interceptor = require('./interceptor').Interceptor,
|
|
12
13
|
HttpObserver = require('../observers/http-observer').HttpObserver,
|
|
@@ -104,8 +105,8 @@ NodeAgent.prototype.init = function(cb) {
|
|
|
104
105
|
self.starttime = Date.now();
|
|
105
106
|
|
|
106
107
|
self.findRoot();
|
|
108
|
+
|
|
107
109
|
Logger.initializer.process();
|
|
108
|
-
|
|
109
110
|
Logger.print('WHATAP-001', 'Start initialize WhaTap Agent...', true);
|
|
110
111
|
|
|
111
112
|
if(self._conf['app.root'] == null || self._conf['app.root'].length == 0) {
|
|
@@ -122,6 +123,11 @@ NodeAgent.prototype.init = function(cb) {
|
|
|
122
123
|
return;
|
|
123
124
|
}
|
|
124
125
|
Logger.print('WHATAP-101', 'Finish initialize configuration...', false);
|
|
126
|
+
if(self._conf['reqlog_enabled'] === true ) {
|
|
127
|
+
Logger.print("WHATAP-REQLOG" , "ReqLog Init Start !!!! " , false);
|
|
128
|
+
RequestLog.initializer.process();
|
|
129
|
+
}
|
|
130
|
+
|
|
125
131
|
self._securityMaster.run( function (err) {
|
|
126
132
|
if(err) {
|
|
127
133
|
Logger.printError('WHATAP-104', 'Failed to connect to whatap server', err, false);
|
package/lib/logger.js
CHANGED
|
@@ -3,305 +3,305 @@
|
|
|
3
3
|
* Use of this source code is governed by a license that
|
|
4
4
|
* can be found in the LICENSE file.
|
|
5
5
|
*/
|
|
6
|
-
var WHATAP_CONF = process.env.WHATAP_CONF || 'whatap';
|
|
6
|
+
var WHATAP_CONF = process.env.WHATAP_CONF || 'whatap';
|
|
7
7
|
|
|
8
|
-
var conf = require('./conf/configure'),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var PID=process.pid;
|
|
14
|
-
|
|
15
|
-
var initializer = {
|
|
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 Logger = {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
8
|
+
var conf = require('./conf/configure'),
|
|
9
|
+
DateUtil = require('./util/dateutil'),
|
|
10
|
+
path = require('path'),
|
|
11
|
+
fs = require('fs');
|
|
12
|
+
|
|
13
|
+
var PID=process.pid;
|
|
14
|
+
|
|
15
|
+
var initializer = {
|
|
16
|
+
last : DateUtil.currentTime(),
|
|
17
|
+
lastDateUnit : DateUtil.getDateUnit(),
|
|
18
|
+
lastFileRotation : true,
|
|
19
|
+
reset : function () {
|
|
20
|
+
if(Logger.printWriter)
|
|
21
|
+
Logger.printWriter.close();
|
|
22
|
+
Logger.logfile = null;
|
|
23
|
+
Logger.openFile();
|
|
24
|
+
},
|
|
25
|
+
process : function () {
|
|
26
|
+
conf = require('./conf/configure');
|
|
27
|
+
var now = DateUtil.currentTime();
|
|
28
|
+
if(now > this.last + DateUtil.MILLIS_PER_HOUR) {
|
|
29
|
+
this.last = now;
|
|
30
|
+
Logger.clearOldLog();
|
|
31
|
+
}
|
|
32
|
+
if(this.lastFileRotation !== conf.log_rotation_enabled
|
|
33
|
+
|| this.lastDateUnit !== DateUtil.getDateUnit()
|
|
34
|
+
|| (Logger.logfile !== null && fs.existsSync(Logger.logfile) == false)) {
|
|
35
|
+
try {
|
|
36
|
+
if(Logger.printWriter){
|
|
37
|
+
Logger.printWriter.close();
|
|
38
|
+
}
|
|
39
|
+
Logger.logfile = null;
|
|
40
|
+
this.lastFileRotation = conf.log_rotation_enabled;
|
|
41
|
+
this.lastDateUnit = DateUtil.getDateUnit();
|
|
42
|
+
} catch(e) {
|
|
43
|
+
console.log(e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
Logger.openFile();
|
|
48
|
+
} catch(e) {
|
|
49
|
+
console.log(e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var Logger = {
|
|
55
|
+
ONAME : null,
|
|
56
|
+
logfile : null,
|
|
57
|
+
lastLog : {},
|
|
58
|
+
printWriter : null,
|
|
59
|
+
printAll : function (id, message, sysout) {
|
|
60
|
+
try{
|
|
61
|
+
var b_msg = this.build(id, message);
|
|
62
|
+
if(this.printWriter != null) {
|
|
63
|
+
this.printWriter.write(b_msg);
|
|
64
|
+
this.printWriter.write('\n');
|
|
65
|
+
} else {
|
|
66
|
+
this.openFile();
|
|
67
|
+
}
|
|
68
|
+
sysout = (sysout || process.env.WHATAP_PRINT);
|
|
69
|
+
if(sysout) {
|
|
70
|
+
console.log(b_msg);
|
|
71
|
+
}
|
|
72
|
+
} catch (e){
|
|
73
|
+
if(sysout) {
|
|
74
|
+
console.log(e);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
print : function (id, message, sysout) {
|
|
79
|
+
if(this.checkOk(id, 10) == false) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
try{
|
|
83
|
+
var b_msg = this.build(id, message);
|
|
84
|
+
if(this.printWriter != null) {
|
|
85
|
+
this.printWriter.write(b_msg);
|
|
86
|
+
this.printWriter.write('\n');
|
|
87
|
+
} else {
|
|
88
|
+
this.openFile();
|
|
89
|
+
}
|
|
90
|
+
sysout = (sysout || process.env.WHATAP_PRINT);
|
|
91
|
+
if(sysout) {
|
|
92
|
+
console.log(b_msg);
|
|
93
|
+
}
|
|
94
|
+
} catch (e){
|
|
95
|
+
if(sysout) {
|
|
96
|
+
console.log(e);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
printError : function (id, message, err, sysout) {
|
|
101
|
+
if(this.checkOk(id, 10) == false) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.print(id, message, false);
|
|
105
|
+
sysout = (sysout || process.env.WHATAP_PRINT);
|
|
106
|
+
if(sysout) {
|
|
107
|
+
console.error(this.build(id, message));
|
|
108
|
+
}
|
|
109
|
+
if(err) {
|
|
110
|
+
if(this.printWriter != null) {
|
|
111
|
+
this.printWriter.write(err.stack);
|
|
112
|
+
this.printWriter.write('\n');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
checkOk : function (id, sec) {
|
|
117
|
+
if(conf.log_print_enabled === false) { return false; }
|
|
118
|
+
if(conf.isIgnoreLog && conf.isIgnoreLog(id)) { return false; }
|
|
119
|
+
|
|
120
|
+
if(Object.keys(Logger.lastLog).length >= 1000) {
|
|
121
|
+
Logger.lastLog = {};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if(sec > 0) {
|
|
125
|
+
var last = Logger.lastLog[id];
|
|
126
|
+
if(last == null) {
|
|
127
|
+
last = 0;
|
|
128
|
+
}
|
|
129
|
+
var now = Date.now();
|
|
130
|
+
if(now < last + sec * 1000) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
Logger.lastLog[id] = now;
|
|
134
|
+
}
|
|
135
|
+
return true;
|
|
136
|
+
},
|
|
137
|
+
build : function (id, message) {
|
|
138
|
+
var str = DateUtil.datetime(Date.now());
|
|
139
|
+
str += ' [';
|
|
140
|
+
str += id;
|
|
141
|
+
str += '] <' + PID + '> ';
|
|
142
|
+
str += message;
|
|
143
|
+
return str;
|
|
144
|
+
},
|
|
145
|
+
openFile : function () {
|
|
146
|
+
if(conf.log_file_enabled === false ) { return; }
|
|
147
|
+
var log_prefix = WHATAP_CONF+"-";
|
|
148
|
+
|
|
149
|
+
var root = conf['app.root'];
|
|
150
|
+
if(root==null || root ==undefined){
|
|
151
|
+
console.log('[WHATAP]Logger Error - WHATAP ROOT DIR IS NULL!!!!!!!!!');
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
var dir = path.join(root, 'logs');
|
|
155
|
+
if(fs.existsSync(dir) == false) {
|
|
156
|
+
fs.mkdirSync(dir);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if(conf.log_rotation_enabled) {
|
|
160
|
+
var file = path.join(dir, log_prefix + DateUtil.yyyymmdd() + '.log');
|
|
161
|
+
this.logfile = file;
|
|
162
|
+
this.printWriter = fs.createWriteStream(file, {flags : 'a'});
|
|
163
|
+
} else {
|
|
164
|
+
var file = path.join(dir, 'whatap.log');
|
|
165
|
+
this.logfile = file;
|
|
166
|
+
this.printWriter = fs.createWriteStream(file, {flags : 'a'});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
},
|
|
170
|
+
clearOldLog : function () {
|
|
171
|
+
if(conf.log_rotation_enabled === false || conf.log_enabled === false) { return; }
|
|
172
|
+
if(conf.log_keep_days <= 0) { return; }
|
|
173
|
+
|
|
174
|
+
var nowUnit = DateUtil.getDateUnit(),
|
|
175
|
+
root = conf['app.root'],
|
|
176
|
+
dir = path.join(root, 'logs'),
|
|
177
|
+
log_prefix = WHATAP_CONF+"-";
|
|
178
|
+
|
|
179
|
+
fs.readdir(dir, function (err, files) {
|
|
180
|
+
|
|
181
|
+
for(var i=0; i<files.length; i++) {
|
|
182
|
+
var stat = fs.statSync(path.join(dir, files[i]));
|
|
183
|
+
if(stat.isDirectory()) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
var name = files[i];
|
|
187
|
+
if(name.indexOf(log_prefix) < 0) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
var x = name.lastIndexOf('.');
|
|
191
|
+
if(x < 0) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
var date = name.substr(log_prefix.length + 1, (x - log_prefix.length - 1));
|
|
195
|
+
if(date.length != 8) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
var d = DateUtil.yyyymmdd(date);
|
|
199
|
+
var fileUnit = DateUtil.getDateUnit(d);
|
|
200
|
+
try {
|
|
201
|
+
if (nowUnit - fileUnit > conflog_keep_days) {
|
|
202
|
+
fs.unlinkSync(path.join(dir, files[i]));
|
|
203
|
+
}
|
|
204
|
+
} catch (e) { }
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
read : function( file, endpos, length , callback) {
|
|
210
|
+
|
|
211
|
+
if ( file == null || length === 0)
|
|
212
|
+
return null;
|
|
213
|
+
if (file.startsWith(WHATAP_CONF) == false)
|
|
214
|
+
return null;
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
var root = conf['app.root'];
|
|
219
|
+
if(root==null ){
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
var dir = path.join(root, 'logs');
|
|
223
|
+
var fileFullPath = path.join(dir, file);
|
|
224
|
+
|
|
225
|
+
if(fs.existsSync(fileFullPath) == false) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
const stats = fs.statSync(fileFullPath);
|
|
229
|
+
|
|
230
|
+
if (endpos < 0) {
|
|
231
|
+
endpos = stats.size;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
var start = Math.max(0, endpos - length);
|
|
235
|
+
|
|
236
|
+
if ( stats.size < start)
|
|
237
|
+
return null;
|
|
238
|
+
|
|
239
|
+
var available = stats.size - start;
|
|
240
|
+
var readable = Math.min(available, length);
|
|
241
|
+
var next=-1;
|
|
242
|
+
var buffer = Buffer.alloc(readable);
|
|
243
|
+
fs.open(fileFullPath, 'r', function (err, fd) {
|
|
244
|
+
fs.read(fd, buffer, 0, buffer.length, start,function(e,l,b){
|
|
245
|
+
next = endpos + l;
|
|
246
|
+
if (next > stats.size) {
|
|
247
|
+
next = -1;
|
|
248
|
+
}
|
|
249
|
+
callback(start, next,b.toString("utf8",0,l)) ;
|
|
250
|
+
});
|
|
251
|
+
fs.close(fd);
|
|
252
|
+
});
|
|
233
253
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
const stats = fs.statSync(dir + '/'+file);
|
|
289
|
-
if(stats){
|
|
290
|
-
o.putLong(file, stats.size);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
} else {
|
|
294
|
-
if (fs.existsSync(dir + "/whatap.log")) {
|
|
295
|
-
const stats = fs.statSync(dir + "/whatap.log");
|
|
296
|
-
o.putLong(file, stats.size);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return o;
|
|
300
|
-
},
|
|
301
|
-
initializer : initializer,
|
|
302
|
-
CODE: {
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
module.exports = Logger;
|
|
254
|
+
},
|
|
255
|
+
getLogFiles : function () {
|
|
256
|
+
var MapValue = require('./value/map-value');
|
|
257
|
+
var log_prefix = WHATAP_CONF+"-";
|
|
258
|
+
|
|
259
|
+
var o = new MapValue();
|
|
260
|
+
if(conf.log_file_enabled === false ) { return o; }
|
|
261
|
+
var root = conf['app.root'];
|
|
262
|
+
if(root==null){
|
|
263
|
+
return o;
|
|
264
|
+
}
|
|
265
|
+
var dir = path.join(root, 'logs');
|
|
266
|
+
if(fs.existsSync(dir) === false) {
|
|
267
|
+
return o;
|
|
268
|
+
}
|
|
269
|
+
var agoOneMonthTime=DateUtil.getMonth(Date.now(), -1);
|
|
270
|
+
|
|
271
|
+
if(conf.log_rotation_enabled) {
|
|
272
|
+
var files = fs.readdirSync(dir);
|
|
273
|
+
files.forEach(function (file) {
|
|
274
|
+
if (file.startsWith(log_prefix) == false) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
var x = file.lastIndexOf('.');
|
|
278
|
+
if (x < 0) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
var date = file.substring(log_prefix.length , x);
|
|
282
|
+
if (date.length != 8) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (DateUtil.yyyymmdd(date) < agoOneMonthTime) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
const stats = fs.statSync(dir + '/'+file);
|
|
289
|
+
if(stats){
|
|
290
|
+
o.putLong(file, stats.size);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
} else {
|
|
294
|
+
if (fs.existsSync(dir + "/whatap.log")) {
|
|
295
|
+
const stats = fs.statSync(dir + "/whatap.log");
|
|
296
|
+
o.putLong(file, stats.size);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return o;
|
|
300
|
+
},
|
|
301
|
+
initializer : initializer,
|
|
302
|
+
CODE: {
|
|
303
|
+
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
module.exports = Logger;
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* can be found in the LICENSE file.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
const { reqlog_x_txid } = require('../conf/config-default');
|
|
7
8
|
const controlHandler = require('../control/control-handler');
|
|
9
|
+
const RequestLog = require('../requestlog');
|
|
8
10
|
var TraceContextManager = require('../trace/trace-context-manager'),
|
|
9
11
|
URLPatternDetector = require('../trace/serviceurl-pattern-detector').Detector,
|
|
10
12
|
DataTextAgent = require('../data/datatext-agent'),
|
|
@@ -124,6 +126,8 @@ HttpObserver.prototype.__createTransactionObserver = function(callback, isHttps,
|
|
|
124
126
|
if (ctx.status >= 4 && ctx.error.isZero()) {
|
|
125
127
|
ctx.error = StatError.addError(obj.statusCode, obj.statusMessage,
|
|
126
128
|
ctx.service_hash);
|
|
129
|
+
ctx.statusCode = obj.statusCode;
|
|
130
|
+
ctx.statusMessage = obj.statusMessage;
|
|
127
131
|
}
|
|
128
132
|
|
|
129
133
|
self.__endTransaction(null, ctx, req, res);
|
|
@@ -356,7 +360,7 @@ HttpObserver.prototype.__endTransaction = function(error, ctx, req, res) {
|
|
|
356
360
|
wtx.endTime = DateUtil.currentTime();
|
|
357
361
|
profile.time = wtx.endTime;
|
|
358
362
|
wtx.elapsed = ctx.getElapsedTime();
|
|
359
|
-
|
|
363
|
+
|
|
360
364
|
ctx.service_hash = HashUtil.hashFromString(ctx.service_name);
|
|
361
365
|
DataTextAgent.SERVICE.add(ctx.service_hash, ctx.service_name);
|
|
362
366
|
|
|
@@ -385,7 +389,7 @@ HttpObserver.prototype.__endTransaction = function(error, ctx, req, res) {
|
|
|
385
389
|
wtx.status = ctx.status;
|
|
386
390
|
|
|
387
391
|
wtx.http_method=TxRecord.HTTP_METHOD[ctx.http_method] || TxRecord.WEB_GET;
|
|
388
|
-
|
|
392
|
+
wtx.http_host = ctx.http_host;
|
|
389
393
|
wtx.mtid=ctx.mtid;
|
|
390
394
|
wtx.mdepth=ctx.mdepth;
|
|
391
395
|
wtx.mcaller=ctx.mcaller_txid;
|
|
@@ -398,7 +402,11 @@ HttpObserver.prototype.__endTransaction = function(error, ctx, req, res) {
|
|
|
398
402
|
|
|
399
403
|
profile.oid = SecurityMaster.OID;
|
|
400
404
|
profile.service = wtx;
|
|
401
|
-
|
|
405
|
+
if(conf.reqlog_enabled === true) {
|
|
406
|
+
ctx.endTime = wtx.endTime;
|
|
407
|
+
ctx.elapsed = wtx.elapsed;
|
|
408
|
+
RequestLog.setRecord(ctx);
|
|
409
|
+
}
|
|
402
410
|
//duplicated executed... so end() first
|
|
403
411
|
TraceContextManager.end(ctx._id);
|
|
404
412
|
setTimeout(function () {
|
|
@@ -406,6 +414,7 @@ HttpObserver.prototype.__endTransaction = function(error, ctx, req, res) {
|
|
|
406
414
|
TraceContextManager.end(ctx._id);
|
|
407
415
|
ctx = null;
|
|
408
416
|
}, 100);
|
|
417
|
+
|
|
409
418
|
} catch (e) {
|
|
410
419
|
Logger.printError('WHATAP-607', 'End transaction error..', e, false);
|
|
411
420
|
TraceContextManager.end(ctx._id);
|
|
@@ -603,7 +612,11 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
|
|
|
603
612
|
if (step.error.isZero()) {
|
|
604
613
|
step.error = StatError.addError(statusCode, response.statusMessage , ctx.service_hash,
|
|
605
614
|
TextTypes.HTTPC_URL, step.url);
|
|
606
|
-
if (ctx.error.isZero()) {
|
|
615
|
+
if (ctx.error.isZero()) {
|
|
616
|
+
ctx.error = step.error;
|
|
617
|
+
ctx.statusCode = statusCode;
|
|
618
|
+
ctx.statusMessage = response.statusMessage;
|
|
619
|
+
}
|
|
607
620
|
}
|
|
608
621
|
}
|
|
609
622
|
})
|
|
@@ -613,7 +626,11 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
|
|
|
613
626
|
if (step.error.isZero()) {
|
|
614
627
|
step.error = StatError.addError(err.code, err.message, ctx.service_hash,
|
|
615
628
|
TextTypes.HTTPC_URL, step.url);
|
|
616
|
-
if (ctx.error.isZero()) {
|
|
629
|
+
if (ctx.error.isZero()) {
|
|
630
|
+
ctx.error = step.error;
|
|
631
|
+
ctx.statusCode = err.code;
|
|
632
|
+
ctx.statusMessage = err.message;
|
|
633
|
+
}
|
|
617
634
|
}
|
|
618
635
|
|
|
619
636
|
endHttpc(ctx, step);
|
|
@@ -661,6 +678,8 @@ HttpObserver.prototype.inject = function( mod, moduleName ) {
|
|
|
661
678
|
step.error = StatError.addError('Timeout','Timeout', ctx.service_hash);
|
|
662
679
|
if (ctx.error.isZero()) {
|
|
663
680
|
ctx.error = step.error;
|
|
681
|
+
ctx.statusCode = 'Timeout';
|
|
682
|
+
ctx.statusMessage = 'Timeout';
|
|
664
683
|
}
|
|
665
684
|
}
|
|
666
685
|
endHttpc(ctx, step);
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2016 the WHATAP project authors. All rights reserved.
|
|
3
|
+
* Use of this source code is governed by a license that
|
|
4
|
+
* can be found in the LICENSE file.
|
|
5
|
+
*/
|
|
6
|
+
var WHATAP_CONF = 'reqlog';
|
|
7
|
+
|
|
8
|
+
var conf = require('./conf/configure'),
|
|
9
|
+
DateUtil = require('./util/dateutil'),
|
|
10
|
+
IPUtil = require('./util/iputil'),
|
|
11
|
+
path = require('path'),
|
|
12
|
+
fs = require('fs'),
|
|
13
|
+
LOGGER = require('./logger');
|
|
14
|
+
|
|
15
|
+
var PID=process.pid;
|
|
16
|
+
|
|
17
|
+
var initializer = {
|
|
18
|
+
last : DateUtil.currentTime(),
|
|
19
|
+
lastDateUnit : DateUtil.getDateUnit(),
|
|
20
|
+
lastFileRotation : true,
|
|
21
|
+
reset : function () {
|
|
22
|
+
if(RequestLog.printWriter) RequestLog.printWriter.close();
|
|
23
|
+
RequestLog.logfile = null;
|
|
24
|
+
RequestLog.openFile();
|
|
25
|
+
},
|
|
26
|
+
process : function () {
|
|
27
|
+
conf = require('./conf/configure');
|
|
28
|
+
var now = DateUtil.currentTime();
|
|
29
|
+
if(now > this.last + DateUtil.MILLIS_PER_HOUR) {
|
|
30
|
+
this.last = now;
|
|
31
|
+
RequestLog.clearOldLog();
|
|
32
|
+
}
|
|
33
|
+
if(this.lastFileRotation !== conf.reqlog_rotation_enabled
|
|
34
|
+
|| this.lastDateUnit !== DateUtil.getDateUnit()
|
|
35
|
+
|| (RequestLog.logfile !== null && fs.existsSync(RequestLog.logfile) == false)) {
|
|
36
|
+
try {
|
|
37
|
+
if(RequestLog.printWriter){
|
|
38
|
+
RequestLog.printWriter.close();
|
|
39
|
+
}
|
|
40
|
+
RequestLog.logfile = null;
|
|
41
|
+
this.lastFileRotation = conf.reqlog_rotation_enabled;
|
|
42
|
+
this.lastDateUnit = DateUtil.getDateUnit();
|
|
43
|
+
} catch(e) {
|
|
44
|
+
console.log(e);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
RequestLog.openFile();
|
|
49
|
+
} catch(e) {
|
|
50
|
+
console.log(e);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
var RequestLog = {
|
|
58
|
+
ONAME : null,
|
|
59
|
+
logfile : null,
|
|
60
|
+
lastLog : {},
|
|
61
|
+
printWriter : null,
|
|
62
|
+
setRecord : async function (ctx) {
|
|
63
|
+
try{
|
|
64
|
+
if(this.printWriter != null) {
|
|
65
|
+
this.buildRecord(ctx).then(e => {
|
|
66
|
+
this.printWriter.write(e + '\n');
|
|
67
|
+
}).catch((err)=> {
|
|
68
|
+
LOGGER.printError('[WHATAP-LOG]' ,'setRecord_1' , err , false);
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
this.openFile();
|
|
72
|
+
}
|
|
73
|
+
} catch (e){
|
|
74
|
+
LOGGER.printError('[WHATAP-LOG]' ,'setRecord_2' , err , false);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
checkOk : function (id, sec) {
|
|
78
|
+
if(Object.keys(RequestLog.lastLog).length >= 1000) {
|
|
79
|
+
RequestLog.lastLog = {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if(sec > 0) {
|
|
83
|
+
var last = RequestLog.lastLog[id];
|
|
84
|
+
if(last == null) {
|
|
85
|
+
last = 0;
|
|
86
|
+
}
|
|
87
|
+
var now = Date.now();
|
|
88
|
+
if(now < last + sec * 1000) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
RequestLog.lastLog[id] = now;
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
},
|
|
95
|
+
buildRecord : async function (ctx) {
|
|
96
|
+
var str = '';
|
|
97
|
+
let seperator = conf.reqlog_seperator;
|
|
98
|
+
str += "stime=" + ctx.start_time;
|
|
99
|
+
if (conf.reqlog_x_etime) {
|
|
100
|
+
str += seperator + "etime=" + ctx.endTime;
|
|
101
|
+
}
|
|
102
|
+
if (conf.reqlog_x_elapsed) {
|
|
103
|
+
str += seperator + "elapsed=" + ctx.elapsed;
|
|
104
|
+
}
|
|
105
|
+
if (conf.reqlog_x_url) {
|
|
106
|
+
str += seperator + "url=" + ctx.service_name;
|
|
107
|
+
}
|
|
108
|
+
if (conf.reqlog_x_httphost && ctx.http_host!=null) {
|
|
109
|
+
str += seperator + "httphost=" + ctx.http_host;
|
|
110
|
+
}
|
|
111
|
+
if (conf.reqlog_x_method) {
|
|
112
|
+
str += seperator + "method=" + ctx.http_method;
|
|
113
|
+
}
|
|
114
|
+
if (conf.reqlog_x_ip && ctx.remoteIp != 0) {
|
|
115
|
+
str += seperator + "ip=" + IPUtil.intToString(ctx.remoteIp);
|
|
116
|
+
}
|
|
117
|
+
if (conf.reqlog_x_status) {
|
|
118
|
+
str += seperator + "status=" + ctx.status;
|
|
119
|
+
}
|
|
120
|
+
/*
|
|
121
|
+
if (conf.reqlog_x_wcid && x.wclientId != 0) {
|
|
122
|
+
str += seperator + "wcid=" + x.wclientId;
|
|
123
|
+
}
|
|
124
|
+
*/
|
|
125
|
+
if (conf.reqlog_x_login && ctx.login != null) {
|
|
126
|
+
str += seperator + "login=" + ctx.login;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (conf.reqlog_x_error && ctx.error != null && ctx.statusMessage !== undefined) {
|
|
130
|
+
str += seperator + "errMsg=" + ctx.statusMessage;
|
|
131
|
+
}
|
|
132
|
+
if (conf.reqlog_x_useragent) {
|
|
133
|
+
str += seperator + "userAgent=" + ctx.userAgentString;
|
|
134
|
+
}
|
|
135
|
+
if (conf.reqlog_x_txid) {
|
|
136
|
+
str += seperator + "txid=" + ctx.txid;
|
|
137
|
+
}
|
|
138
|
+
if (ctx.custid != null) {
|
|
139
|
+
if (conf.reqlog_x_custid) {
|
|
140
|
+
str += seperator + "custid=" + ctx.custid;
|
|
141
|
+
} else if (conf.reqlog_x_gtid) {
|
|
142
|
+
str += seperator + "gtid=" + ctx.custid;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (conf.reqlog_x_mtid && ctx.mtid != 0) {
|
|
146
|
+
str += seperator + "mtid=" + ctx.mtid;
|
|
147
|
+
if (conf.reqlog_x_mdepth) {
|
|
148
|
+
str += seperator + "mdepth=" + ctx.mdepth;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/*
|
|
152
|
+
if (conf.reqlog_x_dbc && x.dbc_time > 0) {
|
|
153
|
+
str += seperator + "dbcTime=" + x.dbc_time;
|
|
154
|
+
}
|
|
155
|
+
*/
|
|
156
|
+
if (conf.reqlog_x_sql && ctx.sql_count > 0) {
|
|
157
|
+
str += seperator + "sqlCnt=" + ctx.sql_count;
|
|
158
|
+
str += seperator + "sqlTime=" + ctx.sql_time;
|
|
159
|
+
}
|
|
160
|
+
if (conf.reqlog_x_httpc && ctx.httpc_count > 0) {
|
|
161
|
+
str += seperator + "httpCallCnt=" + ctx.httpc_count;
|
|
162
|
+
str += seperator + "httpCallTime=" + ctx.httpc_time;
|
|
163
|
+
}
|
|
164
|
+
if (conf.reqlog_x_rs && ctx.rs_count > 0) {
|
|
165
|
+
str += seperator + "rsCnt=" + ctx.rs_count;
|
|
166
|
+
str += seperator + "rsTime=" + ctx.rs_time;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return str;
|
|
170
|
+
},
|
|
171
|
+
openFile : function () {
|
|
172
|
+
if(conf.log_file_enabled === false ) { return; }
|
|
173
|
+
var log_prefix = WHATAP_CONF+"-";
|
|
174
|
+
|
|
175
|
+
var root = conf['app.root'];
|
|
176
|
+
if(root==null || root ==undefined){
|
|
177
|
+
console.log('[WHATAP]RequestLog Error - WHATAP ROOT DIR IS NULL!!!!!!!!!');
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
var dir = path.join(root, 'logs');
|
|
181
|
+
if(fs.existsSync(dir) == false) {
|
|
182
|
+
fs.mkdirSync(dir);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if(conf.reqlog_rotation_enabled) {
|
|
186
|
+
var file = path.join(dir, log_prefix + DateUtil.yyyymmdd() + '.log');
|
|
187
|
+
this.logfile = file;
|
|
188
|
+
this.printWriter = fs.createWriteStream(file, {flags : 'a'});
|
|
189
|
+
} else {
|
|
190
|
+
var file = path.join(dir, 'reqlog.log');
|
|
191
|
+
this.logfile = file;
|
|
192
|
+
this.printWriter = fs.createWriteStream(file, {flags : 'a'});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
},
|
|
196
|
+
clearOldLog : function () {
|
|
197
|
+
if(conf.reqlog_rotation_enabled === false || conf.reqlog_enabled === false) { return; }
|
|
198
|
+
if(conf.reqlog_keep_days <= 0) { return; }
|
|
199
|
+
|
|
200
|
+
var nowUnit = DateUtil.getDateUnit(),
|
|
201
|
+
root = conf['app.root'],
|
|
202
|
+
dir = path.join(root, 'logs'),
|
|
203
|
+
log_prefix = WHATAP_CONF+"-";
|
|
204
|
+
|
|
205
|
+
fs.readdir(dir, function (err, files) {
|
|
206
|
+
|
|
207
|
+
for(var i=0; i<files.length; i++) {
|
|
208
|
+
var stat = fs.statSync(path.join(dir, files[i]));
|
|
209
|
+
if(stat.isDirectory()) {
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
var name = files[i];
|
|
213
|
+
if(name.indexOf(log_prefix) < 0) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
var x = name.lastIndexOf('.');
|
|
217
|
+
if(x < 0) {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
var date = name.substr(log_prefix.length + 1, (x - log_prefix.length - 1));
|
|
221
|
+
if(date.length != 8) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
var d = DateUtil.yyyymmdd(date);
|
|
225
|
+
var fileUnit = DateUtil.getDateUnit(d);
|
|
226
|
+
try {
|
|
227
|
+
if (nowUnit - fileUnit > conflog_keep_days) {
|
|
228
|
+
fs.unlinkSync(path.join(dir, files[i]));
|
|
229
|
+
}
|
|
230
|
+
} catch (e) { }
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
});
|
|
234
|
+
},
|
|
235
|
+
read : function( file, endpos, length , callback) {
|
|
236
|
+
|
|
237
|
+
if ( file == null || length === 0)
|
|
238
|
+
return null;
|
|
239
|
+
if (file.startsWith(WHATAP_CONF) == false) return null;
|
|
240
|
+
|
|
241
|
+
var root = conf['app.root'];
|
|
242
|
+
if(root==null ){
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
var dir = path.join(root, 'logs');
|
|
246
|
+
var fileFullPath = path.join(dir, file);
|
|
247
|
+
|
|
248
|
+
if(fs.existsSync(fileFullPath) == false) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
const stats = fs.statSync(fileFullPath);
|
|
252
|
+
|
|
253
|
+
if (endpos < 0) {
|
|
254
|
+
endpos = stats.size;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
var start = Math.max(0, endpos - length);
|
|
258
|
+
|
|
259
|
+
if ( stats.size < start)
|
|
260
|
+
return null;
|
|
261
|
+
|
|
262
|
+
var available = stats.size - start;
|
|
263
|
+
var readable = Math.min(available, length);
|
|
264
|
+
var next=-1;
|
|
265
|
+
var buffer = Buffer.alloc(readable);
|
|
266
|
+
fs.open(fileFullPath, 'r', function (err, fd) {
|
|
267
|
+
fs.read(fd, buffer, 0, buffer.length, start,function(e,l,b){
|
|
268
|
+
next = endpos + l;
|
|
269
|
+
if (next > stats.size) {
|
|
270
|
+
next = -1;
|
|
271
|
+
}
|
|
272
|
+
callback(start, next,b.toString("utf8",0,l)) ;
|
|
273
|
+
});
|
|
274
|
+
fs.close(fd);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
},
|
|
278
|
+
getLogFiles : function () {
|
|
279
|
+
var MapValue = require('./value/map-value');
|
|
280
|
+
var log_prefix = WHATAP_CONF+"-";
|
|
281
|
+
|
|
282
|
+
var o = new MapValue();
|
|
283
|
+
if(conf.log_file_enabled === false ) { return o; }
|
|
284
|
+
var root = conf['app.root'];
|
|
285
|
+
if(root==null){
|
|
286
|
+
return o;
|
|
287
|
+
}
|
|
288
|
+
var dir = path.join(root, 'logs');
|
|
289
|
+
if(fs.existsSync(dir) === false) {
|
|
290
|
+
return o;
|
|
291
|
+
}
|
|
292
|
+
var agoOneMonthTime=DateUtil.getMonth(Date.now(), -1);
|
|
293
|
+
|
|
294
|
+
if(conf.reqlog_rotation_enabled) {
|
|
295
|
+
var files = fs.readdirSync(dir);
|
|
296
|
+
files.forEach(function (file) {
|
|
297
|
+
if (file.startsWith(log_prefix) == false) {
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
var x = file.lastIndexOf('.');
|
|
301
|
+
if (x < 0) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
var date = file.substring(log_prefix.length , x);
|
|
305
|
+
if (date.length != 8) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (DateUtil.yyyymmdd(date) < agoOneMonthTime) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
const stats = fs.statSync(dir + '/'+file);
|
|
312
|
+
if(stats){
|
|
313
|
+
o.putLong(file, stats.size);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
} else {
|
|
317
|
+
if (fs.existsSync(dir + "/reqlog.log")) {
|
|
318
|
+
const stats = fs.statSync(dir + "/reqlog.log");
|
|
319
|
+
o.putLong(file, stats.size);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return o;
|
|
323
|
+
},
|
|
324
|
+
initializer : initializer
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
module.exports = RequestLog;
|
|
@@ -104,10 +104,11 @@ TraceContext.prototype.footprint=function(desc){
|
|
|
104
104
|
}
|
|
105
105
|
TraceContext.prototype.getElapsedTime = function () {
|
|
106
106
|
return Date.now() - this.start_time;
|
|
107
|
-
}
|
|
107
|
+
}
|
|
108
108
|
TraceContext.prototype.resetStartTime = function () {
|
|
109
109
|
this.start_time = Date.now();
|
|
110
|
-
}
|
|
110
|
+
}
|
|
111
|
+
|
|
111
112
|
var poids= new StringKeyLinkedMap(7, 1).setMax(301);
|
|
112
113
|
TraceContext.prototype.setCallerPOID= function (poidStr) {
|
|
113
114
|
try {
|
package/package.json
CHANGED