@wutiange/log-listener-plugin 1.3.0-alpha.1 → 1.3.0-alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -201
- package/README.md +2 -2
- package/console.ts +21 -0
- package/dist/src/HTTPInterceptor.d.ts +48 -0
- package/dist/src/HTTPInterceptor.js +202 -0
- package/dist/src/HTTPInterceptor.js.map +1 -0
- package/dist/src/logPlugin.d.ts +19 -20
- package/dist/src/logPlugin.js +108 -122
- package/dist/src/logPlugin.js.map +1 -1
- package/fetch.ts +39 -0
- package/index.ts +3 -0
- package/package.json +49 -47
- package/src/HTTPInterceptor.ts +319 -0
- package/src/__tests__/console.test.ts +25 -25
- package/src/common.ts +4 -4
- package/src/logPlugin.ts +238 -229
- package/src/server.ts +66 -66
- package/src/utils.ts +47 -47
- package/dist/packages/network-logger/Logger.d.ts +0 -28
- package/dist/packages/network-logger/Logger.js +0 -192
- package/dist/packages/network-logger/Logger.js.map +0 -1
- package/dist/packages/network-logger/NetworkRequestInfo.d.ts +0 -37
- package/dist/packages/network-logger/NetworkRequestInfo.js +0 -151
- package/dist/packages/network-logger/NetworkRequestInfo.js.map +0 -1
- package/dist/packages/network-logger/constant.d.ts +0 -2
- package/dist/packages/network-logger/constant.js +0 -6
- package/dist/packages/network-logger/constant.js.map +0 -1
- package/dist/packages/network-logger/types.d.ts +0 -14
- package/dist/packages/network-logger/types.js +0 -3
- package/dist/packages/network-logger/types.js.map +0 -1
- package/dist/packages/network-logger/utils/debounce.d.ts +0 -2
- package/dist/packages/network-logger/utils/debounce.js +0 -20
- package/dist/packages/network-logger/utils/debounce.js.map +0 -1
- package/dist/packages/network-logger/utils/extractHost.d.ts +0 -2
- package/dist/packages/network-logger/utils/extractHost.js +0 -9
- package/dist/packages/network-logger/utils/extractHost.js.map +0 -1
- package/dist/packages/network-logger/utils/fromEntries.d.ts +0 -2
- package/dist/packages/network-logger/utils/fromEntries.js +0 -8
- package/dist/packages/network-logger/utils/fromEntries.js.map +0 -1
- package/dist/packages/network-logger/utils/logger.d.ts +0 -1
- package/dist/packages/network-logger/utils/logger.js +0 -6
- package/dist/packages/network-logger/utils/logger.js.map +0 -1
- package/dist/src/CompatibilityManager.d.ts +0 -27
- package/dist/src/CompatibilityManager.js +0 -82
- package/dist/src/CompatibilityManager.js.map +0 -1
- package/dist/src/console.d.ts +0 -1
- package/dist/src/console.js +0 -20
- package/dist/src/console.js.map +0 -1
- package/dist/src/fetch.d.ts +0 -1
- package/dist/src/fetch.js +0 -48
- package/dist/src/fetch.js.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -8
- package/dist/src/index.js.map +0 -1
- package/packages/network-logger/Logger.ts +0 -274
- package/packages/network-logger/NetworkRequestInfo.ts +0 -161
- package/packages/network-logger/constant.ts +0 -3
- package/packages/network-logger/types.ts +0 -36
- package/packages/network-logger/utils/debounce.ts +0 -21
- package/packages/network-logger/utils/extractHost.ts +0 -7
- package/packages/network-logger/utils/fromEntries.ts +0 -7
- package/packages/network-logger/utils/logger.ts +0 -2
- package/src/CompatibilityManager.ts +0 -71
@@ -0,0 +1,202 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.httpInterceptor = void 0;
|
16
|
+
const XHRInterceptor_1 = __importDefault(require("react-native/Libraries/Network/XHRInterceptor"));
|
17
|
+
const FileReader_1 = __importDefault(require("react-native/Libraries/Blob/FileReader"));
|
18
|
+
const extractHost = (url) => {
|
19
|
+
var _a, _b;
|
20
|
+
const host = ((_b = (_a = url.split('//')[1]) === null || _a === void 0 ? void 0 : _a.split(':')[0]) === null || _b === void 0 ? void 0 : _b.split('/')[0]) || undefined;
|
21
|
+
return host;
|
22
|
+
};
|
23
|
+
const generateUniqueId = () => {
|
24
|
+
return Date.now().toString(36) + Math.random().toString(36).substr(2);
|
25
|
+
};
|
26
|
+
const parseResponseBlob = (response) => __awaiter(void 0, void 0, void 0, function* () {
|
27
|
+
const blobReader = new FileReader_1.default();
|
28
|
+
blobReader.readAsText(response);
|
29
|
+
return yield new Promise((resolve, reject) => {
|
30
|
+
const handleError = () => reject(blobReader.error);
|
31
|
+
blobReader.addEventListener('load', () => {
|
32
|
+
resolve(blobReader.result);
|
33
|
+
});
|
34
|
+
blobReader.addEventListener('error', handleError);
|
35
|
+
blobReader.addEventListener('abort', handleError);
|
36
|
+
});
|
37
|
+
});
|
38
|
+
const getResponseBody = (responseType, response) => __awaiter(void 0, void 0, void 0, function* () {
|
39
|
+
try {
|
40
|
+
const body = yield (responseType !== 'blob'
|
41
|
+
? response
|
42
|
+
: parseResponseBlob(response));
|
43
|
+
return JSON.parse(body);
|
44
|
+
}
|
45
|
+
catch (error) {
|
46
|
+
return null;
|
47
|
+
}
|
48
|
+
});
|
49
|
+
class HTTPInterceptor {
|
50
|
+
constructor() {
|
51
|
+
this.allRequests = new Map();
|
52
|
+
this.userListeners = [];
|
53
|
+
this.enabled = false;
|
54
|
+
this.addListener = (eventName, listener) => {
|
55
|
+
if (this.userListeners.find(([name, tempListener]) => name === eventName && tempListener === listener)) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
this.userListeners.push([eventName, listener]);
|
59
|
+
return () => {
|
60
|
+
this.userListeners = this.userListeners.filter(([name, tempListener]) => name !== eventName || tempListener !== listener);
|
61
|
+
};
|
62
|
+
};
|
63
|
+
this.removeListener = (eventName, listener) => {
|
64
|
+
this.userListeners = this.userListeners.filter(([name, tempListener]) => name !== eventName || tempListener !== listener);
|
65
|
+
};
|
66
|
+
this.listenerHandle = (eventName, data) => {
|
67
|
+
this.userListeners.forEach(([name, listener]) => __awaiter(this, void 0, void 0, function* () {
|
68
|
+
if (name === eventName) {
|
69
|
+
yield listener(data);
|
70
|
+
}
|
71
|
+
}));
|
72
|
+
};
|
73
|
+
this.openHandle = (method, url, xhr) => {
|
74
|
+
if (this.ignoredHosts) {
|
75
|
+
const host = extractHost(url);
|
76
|
+
if (host && this.ignoredHosts.has(host)) {
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
if (this.ignoredUrls && this.ignoredUrls.has(url)) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
if (this.ignoredPatterns) {
|
84
|
+
if (this.ignoredPatterns.some(pattern => pattern.test(`${method} ${url}`))) {
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
xhr.uniqueId = HTTPInterceptor._index + generateUniqueId();
|
89
|
+
const newRequest = {
|
90
|
+
id: xhr.uniqueId,
|
91
|
+
method,
|
92
|
+
url,
|
93
|
+
};
|
94
|
+
this.allRequests.set(xhr.uniqueId, newRequest);
|
95
|
+
this.listenerHandle('open', newRequest);
|
96
|
+
};
|
97
|
+
this.requestHeaderHandle = (header, value, xhr) => {
|
98
|
+
const currentRequest = this.allRequests.get(xhr.uniqueId);
|
99
|
+
if (!currentRequest) {
|
100
|
+
return;
|
101
|
+
}
|
102
|
+
if (!currentRequest.requestHeaders) {
|
103
|
+
currentRequest.requestHeaders = {};
|
104
|
+
}
|
105
|
+
currentRequest.requestHeaders[header] = value;
|
106
|
+
this.listenerHandle('requestHeader', currentRequest);
|
107
|
+
};
|
108
|
+
this.headerReceivedHandle = (responseContentType, responseSize, responseHeaders, xhr) => {
|
109
|
+
const currentRequest = this.allRequests.get(xhr.uniqueId);
|
110
|
+
if (!currentRequest) {
|
111
|
+
return;
|
112
|
+
}
|
113
|
+
currentRequest.responseContentType = responseContentType;
|
114
|
+
currentRequest.responseSize = responseSize;
|
115
|
+
currentRequest.responseHeaders = xhr.responseHeaders;
|
116
|
+
this.listenerHandle('headerReceived', currentRequest);
|
117
|
+
};
|
118
|
+
this.responseHandle = (status, timeout, response, responseURL, responseType, xhr) => __awaiter(this, void 0, void 0, function* () {
|
119
|
+
var _a;
|
120
|
+
const currentRequest = this.allRequests.get(xhr.uniqueId);
|
121
|
+
if (!currentRequest) {
|
122
|
+
return;
|
123
|
+
}
|
124
|
+
currentRequest.endTime = Date.now();
|
125
|
+
currentRequest.status = status;
|
126
|
+
currentRequest.timeout = timeout;
|
127
|
+
currentRequest.responseData = yield getResponseBody(responseType, response);
|
128
|
+
currentRequest.responseURL = responseURL;
|
129
|
+
currentRequest.responseType = responseType;
|
130
|
+
currentRequest.duration =
|
131
|
+
currentRequest.endTime - ((_a = currentRequest.startTime) !== null && _a !== void 0 ? _a : 0);
|
132
|
+
this.listenerHandle('response', currentRequest);
|
133
|
+
this.allRequests.delete(xhr.uniqueId);
|
134
|
+
});
|
135
|
+
this.sendHandle = (data, xhr) => {
|
136
|
+
const currentRequest = this.allRequests.get(xhr.uniqueId);
|
137
|
+
if (!currentRequest) {
|
138
|
+
return;
|
139
|
+
}
|
140
|
+
try {
|
141
|
+
currentRequest.requestData = JSON.parse(data);
|
142
|
+
}
|
143
|
+
catch (error) {
|
144
|
+
currentRequest.requestData = null;
|
145
|
+
}
|
146
|
+
currentRequest.startTime = Date.now();
|
147
|
+
this.listenerHandle('send', currentRequest);
|
148
|
+
};
|
149
|
+
this.enable = (options) => {
|
150
|
+
try {
|
151
|
+
if (this.enabled ||
|
152
|
+
(XHRInterceptor_1.default.isInterceptorEnabled() && !(options === null || options === void 0 ? void 0 : options.forceEnable))) {
|
153
|
+
if (!this.enabled) {
|
154
|
+
console.warn('network interceptor has not been enabled as another interceptor is already running (e.g. another debugging program). Use option `forceEnable: true` to override this behaviour.');
|
155
|
+
}
|
156
|
+
return;
|
157
|
+
}
|
158
|
+
if (options === null || options === void 0 ? void 0 : options.ignoredHosts) {
|
159
|
+
if (!Array.isArray(options.ignoredHosts) ||
|
160
|
+
typeof options.ignoredHosts[0] !== 'string') {
|
161
|
+
console.warn('ignoredHosts must be an array of strings. The logger has not been started.');
|
162
|
+
return;
|
163
|
+
}
|
164
|
+
this.ignoredHosts = new Set(options.ignoredHosts);
|
165
|
+
}
|
166
|
+
if (options === null || options === void 0 ? void 0 : options.ignoredPatterns) {
|
167
|
+
this.ignoredPatterns = options.ignoredPatterns;
|
168
|
+
}
|
169
|
+
if (options === null || options === void 0 ? void 0 : options.ignoredUrls) {
|
170
|
+
if (!Array.isArray(options.ignoredUrls) ||
|
171
|
+
typeof options.ignoredUrls[0] !== 'string') {
|
172
|
+
console.warn('ignoredUrls must be an array of strings. The logger has not been started.');
|
173
|
+
return;
|
174
|
+
}
|
175
|
+
this.ignoredUrls = new Set(options.ignoredUrls);
|
176
|
+
}
|
177
|
+
XHRInterceptor_1.default.setOpenCallback(this.openHandle);
|
178
|
+
XHRInterceptor_1.default.setRequestHeaderCallback(this.requestHeaderHandle);
|
179
|
+
XHRInterceptor_1.default.setHeaderReceivedCallback(this.headerReceivedHandle);
|
180
|
+
XHRInterceptor_1.default.setSendCallback(this.sendHandle);
|
181
|
+
XHRInterceptor_1.default.setResponseCallback(this.responseHandle);
|
182
|
+
XHRInterceptor_1.default.enableInterception();
|
183
|
+
this.enabled = true;
|
184
|
+
}
|
185
|
+
catch (error) { }
|
186
|
+
};
|
187
|
+
this.disable = () => {
|
188
|
+
if (!this.enabled) {
|
189
|
+
return;
|
190
|
+
}
|
191
|
+
XHRInterceptor_1.default.disableInterception();
|
192
|
+
this.enabled = false;
|
193
|
+
};
|
194
|
+
}
|
195
|
+
removeAllListener() {
|
196
|
+
this.userListeners = [];
|
197
|
+
}
|
198
|
+
}
|
199
|
+
HTTPInterceptor._index = 0;
|
200
|
+
const httpInterceptor = new HTTPInterceptor();
|
201
|
+
exports.httpInterceptor = httpInterceptor;
|
202
|
+
//# sourceMappingURL=HTTPInterceptor.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"HTTPInterceptor.js","sourceRoot":"","sources":["../../src/HTTPInterceptor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,mGAA2E;AAE3E,wFAAoE;AAqDpE,MAAM,WAAW,GAAG,CAAC,GAAW,EAAE,EAAE;;IAClC,MAAM,IAAI,GAAG,CAAA,MAAA,MAAA,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,0CAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,0CAAE,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,KAAI,SAAS,CAAC;IAE3E,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAEF,MAAM,gBAAgB,GAAG,GAAG,EAAE;IAC5B,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,CAAO,QAAgB,EAAE,EAAE;IACnD,MAAM,UAAU,GAAG,IAAI,oBAAc,EAAE,CAAC;IACxC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEhC,OAAO,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnD,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAEnD,UAAU,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACvC,OAAO,CAAC,UAAU,CAAC,MAAM,C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C;wBACD,OAAO,CAAC,IAAI,CACV,2EAA2E,CAC5E,CAAC;wBACF,OAAO;oBACT,CAAC;oBACD,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;gBAClD,CAAC;gBACD,wBAAc,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAChD,wBAAc,CAAC,wBAAwB,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;gBAClE,wBAAc,CAAC,yBAAyB,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;gBACpE,wBAAc,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAChD,wBAAc,CAAC,mBAAmB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;gBACxD,wBAAc,CAAC,kBAAkB,EAAE,CAAC;gBACpC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACtB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC,CAAA,CAAC;QACpB,CAAC,CAAC;QAEF,YAAO,GAAG,GAAG,EAAE;YACb,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClB,OAAO;YACT,CAAC;YACD,wBAAc,CAAC,mBAAmB,EAAE,CAAC;YACrC,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,CAAC,CAAA;IACH,CAAC;IA3KC,iBAAiB;QACf,IAAI,CAAC,aAAa,GAAG,EAAE,CAAC;IAC1B,CAAC;;AAhDc,sBAAM,GAAG,CAAC,AAAJ,CAAK;AA2N5B,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAG5C,0CAAe"}
|
package/dist/src/logPlugin.d.ts
CHANGED
@@ -2,30 +2,29 @@ declare class LogPlugin {
|
|
2
2
|
private server;
|
3
3
|
private baseData;
|
4
4
|
private timeout;
|
5
|
-
private networkLogger;
|
6
5
|
private host;
|
7
6
|
private isAuto;
|
8
|
-
auto()
|
9
|
-
unAuto()
|
10
|
-
startRecordLog()
|
11
|
-
stopRecordLog()
|
12
|
-
startRecordNetwork()
|
13
|
-
setBaseUrl(url: string)
|
14
|
-
setTimeout(timeout: number)
|
15
|
-
getTimeout()
|
16
|
-
setBaseData(data?: Record<string, any>)
|
7
|
+
auto: () => void;
|
8
|
+
unAuto: () => void;
|
9
|
+
startRecordLog: () => void;
|
10
|
+
stopRecordLog: () => void;
|
11
|
+
startRecordNetwork: () => void;
|
12
|
+
setBaseUrl: (url: string) => void;
|
13
|
+
setTimeout: (timeout: number) => void;
|
14
|
+
getTimeout: () => number;
|
15
|
+
setBaseData: (data?: Record<string, any>) => void;
|
17
16
|
private _log;
|
18
|
-
tag(tag: string, ...data: any[])
|
19
|
-
log(...data: any[])
|
20
|
-
warn(...data: any[])
|
21
|
-
error(...data: any[])
|
22
|
-
uniqueReq(uniqueId: string | undefined, input: RequestInfo | URL, init?: RequestInit)
|
17
|
+
tag: (tag: string, ...data: any[]) => void;
|
18
|
+
log: (...data: any[]) => void;
|
19
|
+
warn: (...data: any[]) => void;
|
20
|
+
error: (...data: any[]) => void;
|
21
|
+
uniqueReq: (uniqueId: string | undefined, input: RequestInfo | URL, init?: RequestInit) => Promise<string>;
|
23
22
|
private _res;
|
24
|
-
resTimeout(uniqueId: string)
|
25
|
-
resResponseError(uniqueId: string)
|
26
|
-
uniqueRes(uniqueId: string, response?: Response)
|
27
|
-
req(input: RequestInfo | URL, init?: RequestInit)
|
28
|
-
res(id: number, response?: Response)
|
23
|
+
resTimeout: (uniqueId: string) => Promise<string>;
|
24
|
+
resResponseError: (uniqueId: string) => Promise<string>;
|
25
|
+
uniqueRes: (uniqueId: string, response?: Response) => Promise<string>;
|
26
|
+
req: (input: RequestInfo | URL, init?: RequestInit) => Promise<string>;
|
27
|
+
res: (id: number, response?: Response) => Promise<string>;
|
29
28
|
}
|
30
29
|
declare const logPlugin: LogPlugin;
|
31
30
|
export { LogPlugin };
|
package/dist/src/logPlugin.js
CHANGED
@@ -14,117 +14,115 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
15
|
exports.LogPlugin = void 0;
|
16
16
|
const server_1 = __importDefault(require("./server"));
|
17
|
-
const Logger_1 = __importDefault(require("../packages/network-logger/Logger"));
|
18
17
|
const utils_1 = require("./utils");
|
19
|
-
const
|
18
|
+
const HTTPInterceptor_1 = require("./HTTPInterceptor");
|
20
19
|
class LogPlugin {
|
21
20
|
constructor() {
|
22
21
|
this.server = null;
|
23
22
|
this.baseData = {};
|
24
23
|
this.timeout = null;
|
25
|
-
this.networkLogger = new Logger_1.default();
|
26
24
|
this.host = '';
|
27
25
|
this.isAuto = false;
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
}
|
41
|
-
startRecordLog() {
|
42
|
-
const common = require('./common');
|
43
|
-
console.log = (...data) => {
|
44
|
-
this.log(...data);
|
45
|
-
common.log(...data);
|
26
|
+
this.auto = () => {
|
27
|
+
if (this.host) {
|
28
|
+
this.startRecordNetwork();
|
29
|
+
this.startRecordLog();
|
30
|
+
}
|
31
|
+
this.isAuto = true;
|
32
|
+
};
|
33
|
+
this.unAuto = () => {
|
34
|
+
this.stopRecordLog();
|
35
|
+
HTTPInterceptor_1.httpInterceptor.disable();
|
36
|
+
HTTPInterceptor_1.httpInterceptor.removeAllListener();
|
37
|
+
this.isAuto = false;
|
46
38
|
};
|
47
|
-
|
48
|
-
|
49
|
-
|
39
|
+
this.startRecordLog = () => {
|
40
|
+
const common = require('./common');
|
41
|
+
console.log = (...data) => {
|
42
|
+
this.log(...data);
|
43
|
+
common.log(...data);
|
44
|
+
};
|
45
|
+
console.warn = (...data) => {
|
46
|
+
this.warn(...data);
|
47
|
+
common.warn(...data);
|
48
|
+
};
|
49
|
+
console.error = (...data) => {
|
50
|
+
this.error(...data);
|
51
|
+
common.error(...data);
|
52
|
+
};
|
50
53
|
};
|
51
|
-
|
52
|
-
|
53
|
-
common.
|
54
|
+
this.stopRecordLog = () => {
|
55
|
+
const common = require('./common');
|
56
|
+
console.log = common.log;
|
57
|
+
console.warn = common.warn;
|
58
|
+
console.error = common.error;
|
54
59
|
};
|
55
|
-
|
56
|
-
|
57
|
-
const common = require('./common');
|
58
|
-
console.log = common.log;
|
59
|
-
console.warn = common.warn;
|
60
|
-
console.error = common.error;
|
61
|
-
}
|
62
|
-
startRecordNetwork() {
|
63
|
-
this.networkLogger.setCallback((data) => __awaiter(this, void 0, void 0, function* () {
|
64
|
-
const sendData = yield CompatibilityManager_1.default.interceptionToNetwork(data);
|
65
|
-
sendData.forEach(e => {
|
60
|
+
this.startRecordNetwork = () => {
|
61
|
+
HTTPInterceptor_1.httpInterceptor.addListener("send", (data) => {
|
66
62
|
var _a;
|
67
|
-
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network(Object.assign(Object.assign({}, this.baseData),
|
63
|
+
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network(Object.assign(Object.assign({}, this.baseData), { url: data.url, id: data.id, method: data.method, headers: data.requestHeaders, body: data.requestData, createTime: data.startTime }));
|
68
64
|
});
|
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
|
-
|
65
|
+
HTTPInterceptor_1.httpInterceptor.addListener("response", (data) => {
|
66
|
+
var _a;
|
67
|
+
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network(Object.assign(Object.assign({}, this.baseData), { headers: data.responseHeaders, body: data.responseData, requestId: data.id, statusCode: data.status, endTime: data.endTime }));
|
68
|
+
});
|
69
|
+
HTTPInterceptor_1.httpInterceptor.enable({
|
70
|
+
ignoredHosts: [(0, utils_1.extractDomain)(this.host)]
|
71
|
+
});
|
72
|
+
};
|
73
|
+
this.setBaseUrl = (url) => {
|
74
|
+
if (!(url === null || url === void 0 ? void 0 : url.trim())) {
|
75
|
+
HTTPInterceptor_1.httpInterceptor.disable();
|
76
|
+
this.stopRecordLog();
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
this.host = url.includes("http") ? url : `http://${url}`;
|
80
|
+
if (this.server) {
|
81
|
+
this.server.updateUrl(url);
|
82
|
+
}
|
83
|
+
else {
|
84
|
+
this.server = new server_1.default(url);
|
85
|
+
}
|
86
|
+
if (this.isAuto) {
|
87
|
+
this.startRecordNetwork();
|
88
|
+
this.startRecordLog();
|
89
|
+
}
|
90
|
+
};
|
91
|
+
this.setTimeout = (timeout) => {
|
92
|
+
var _a;
|
93
|
+
if (typeof timeout === 'number') {
|
94
|
+
this.timeout = timeout;
|
95
|
+
(_a = this.server) === null || _a === void 0 ? void 0 : _a.updateTimeout(this.timeout);
|
96
|
+
}
|
97
|
+
};
|
98
|
+
this.getTimeout = () => {
|
99
|
+
if (typeof this.timeout === 'number') {
|
100
|
+
return this.timeout;
|
101
|
+
}
|
102
|
+
return null;
|
103
|
+
};
|
104
|
+
this.setBaseData = (data = {}) => {
|
105
|
+
this.baseData = data;
|
106
|
+
};
|
107
|
+
this._log = (level, tag, ...data) => {
|
108
|
+
var _a;
|
109
|
+
const sendData = Object.assign(Object.assign({}, this.baseData), { message: data, tag, level: level !== null && level !== void 0 ? level : 'log', createTime: Date.now() });
|
110
|
+
(_a = this.server) === null || _a === void 0 ? void 0 : _a.log(sendData);
|
111
|
+
};
|
112
|
+
this.tag = (tag, ...data) => {
|
113
|
+
this._log('log', tag, ...data);
|
114
|
+
};
|
115
|
+
this.log = (...data) => {
|
116
|
+
this._log('log', 'default', ...data);
|
117
|
+
};
|
118
|
+
this.warn = (...data) => {
|
119
|
+
this._log('warn', 'default', ...data);
|
120
|
+
};
|
121
|
+
this.error = (...data) => {
|
122
|
+
this._log('error', 'default', ...data);
|
123
|
+
};
|
124
|
+
this.uniqueReq = (uniqueId, input, init) => __awaiter(this, void 0, void 0, function* () {
|
125
|
+
var _a, _b, _c;
|
128
126
|
let url = null;
|
129
127
|
let method = (_a = init === null || init === void 0 ? void 0 : init.method) !== null && _a !== void 0 ? _a : 'get';
|
130
128
|
let headers = init === null || init === void 0 ? void 0 : init.headers;
|
@@ -145,38 +143,26 @@ class LogPlugin {
|
|
145
143
|
headers,
|
146
144
|
body, createTime: Date.now() }));
|
147
145
|
});
|
148
|
-
|
149
|
-
|
150
|
-
var _a;
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
146
|
+
this._res = (uniqueId, id, response) => __awaiter(this, void 0, void 0, function* () {
|
147
|
+
var _d;
|
152
148
|
const body = yield (response === null || response === void 0 ? void 0 : response.text());
|
153
|
-
return (
|
149
|
+
return (_d = this.server) === null || _d === void 0 ? void 0 : _d.network(Object.assign(Object.assign({}, this.baseData), { headers: (response === null || response === void 0 ? void 0 : response.headers).map, body, requestId: uniqueId !== null && uniqueId !== void 0 ? uniqueId : Number(id), statusCode: response === null || response === void 0 ? void 0 : response.status, endTime: Date.now() }));
|
154
150
|
});
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
return __awaiter(this, void 0, void 0, function* () {
|
159
|
-
return (_a = this.server) === null || _a === void 0 ? void 0 : _a.network(Object.assign(Object.assign({}, this.baseData), { isTimeout: true, requestId: uniqueId }));
|
151
|
+
this.resTimeout = (uniqueId) => __awaiter(this, void 0, void 0, function* () {
|
152
|
+
var _e;
|
153
|
+
return (_e = this.server) === null || _e === void 0 ? void 0 : _e.network(Object.assign(Object.assign({}, this.baseData), { isTimeout: true, requestId: uniqueId }));
|
160
154
|
});
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
return __awaiter(this, void 0, void 0, function* () {
|
165
|
-
return (_a = this.server) === null || _a === void 0 ? void 0 : _a.network(Object.assign(Object.assign({}, this.baseData), { isResponseError: true, requestId: uniqueId }));
|
155
|
+
this.resResponseError = (uniqueId) => __awaiter(this, void 0, void 0, function* () {
|
156
|
+
var _f;
|
157
|
+
return (_f = this.server) === null || _f === void 0 ? void 0 : _f.network(Object.assign(Object.assign({}, this.baseData), { isResponseError: true, requestId: uniqueId }));
|
166
158
|
});
|
167
|
-
|
168
|
-
uniqueRes(uniqueId, response) {
|
169
|
-
return __awaiter(this, void 0, void 0, function* () {
|
159
|
+
this.uniqueRes = (uniqueId, response) => __awaiter(this, void 0, void 0, function* () {
|
170
160
|
return this._res(uniqueId, undefined, response);
|
171
161
|
});
|
172
|
-
|
173
|
-
req(input, init) {
|
174
|
-
return __awaiter(this, void 0, void 0, function* () {
|
162
|
+
this.req = (input, init) => __awaiter(this, void 0, void 0, function* () {
|
175
163
|
return this.uniqueReq(undefined, input, init);
|
176
164
|
});
|
177
|
-
|
178
|
-
res(id, response) {
|
179
|
-
return __awaiter(this, void 0, void 0, function* () {
|
165
|
+
this.res = (id, response) => __awaiter(this, void 0, void 0, function* () {
|
180
166
|
return this._res(undefined, id, response);
|
181
167
|
});
|
182
168
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logPlugin.js","sourceRoot":"","sources":["../../src/logPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B
|
1
|
+
{"version":3,"file":"logPlugin.js","sourceRoot":"","sources":["../../src/logPl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
3
|
+
* @deprecated 不需要手动导入文件,使用 logger.auto 就会自动开始收集日志
|
4
|
+
*/
|
5
|
+
import logger from './index';
|
6
|
+
import {sleep} from './src/utils';
|
7
|
+
|
8
|
+
const common = require('./src/common');
|
9
|
+
// @ts-ignore
|
10
|
+
global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
11
|
+
const uniqueId = (Date.now() + Math.random()).toString(16);
|
12
|
+
logger.uniqueReq(uniqueId, input, init);
|
13
|
+
let isFetchFinished = false;
|
14
|
+
let isTimeout = false;
|
15
|
+
const timeout = logger.getTimeout()
|
16
|
+
if (timeout !== null) {
|
17
|
+
sleep(timeout).then(() => {
|
18
|
+
if (!isFetchFinished) {
|
19
|
+
isTimeout = true;
|
20
|
+
logger.resTimeout(uniqueId);
|
21
|
+
}
|
22
|
+
});
|
23
|
+
}
|
24
|
+
|
25
|
+
try {
|
26
|
+
const response = await common.tempFetch(input, init);
|
27
|
+
isFetchFinished = true;
|
28
|
+
if (response instanceof Response && !isTimeout) {
|
29
|
+
logger.uniqueRes(uniqueId, response.clone());
|
30
|
+
}
|
31
|
+
return response;
|
32
|
+
} catch (error) {
|
33
|
+
isFetchFinished = true;
|
34
|
+
if (!isTimeout) {
|
35
|
+
logger.resResponseError(uniqueId);
|
36
|
+
}
|
37
|
+
throw new Error(error);
|
38
|
+
}
|
39
|
+
};
|
package/index.ts
ADDED