@wutiange/log-listener-plugin 1.3.0-alpha.2 → 1.3.0-alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- package/console.ts +21 -0
- package/fetch.ts +39 -0
- package/index.ts +3 -0
- package/package.json +8 -6
- package/dist/server.d.ts +0 -10
- package/dist/server.js +0 -45
- package/dist/server.js.map +0 -1
package/console.ts
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview
|
3
|
+
* @deprecated 不需要手动导入文件,使用 logger.auto 就会自动开始收集日志
|
4
|
+
*/
|
5
|
+
|
6
|
+
import logger from './src/logPlugin';
|
7
|
+
const common = require('./src/common');
|
8
|
+
console.log = (...data: any[]) => {
|
9
|
+
logger.log(...data);
|
10
|
+
common.log(...data);
|
11
|
+
};
|
12
|
+
|
13
|
+
console.warn = (...data: any[]) => {
|
14
|
+
logger.warn(...data);
|
15
|
+
common.warn(...data);
|
16
|
+
};
|
17
|
+
|
18
|
+
console.error = (...data: any[]) => {
|
19
|
+
logger.error(...data);
|
20
|
+
common.error(...data);
|
21
|
+
};
|
package/fetch.ts
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview
|
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
package/package.json
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wutiange/log-listener-plugin",
|
3
|
-
"version": "1.3.0-alpha.
|
3
|
+
"version": "1.3.0-alpha.3",
|
4
4
|
"description": "这是log-record的插件,如果需要使用这个日志监听,那么就需要把这个插件安装到项目中",
|
5
|
-
"main": "dist/
|
6
|
-
"types": "dist/
|
7
|
-
"source": "
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"types": "dist/index.d.ts",
|
7
|
+
"source": "index.ts",
|
8
8
|
"repository": {
|
9
9
|
"url": "https://github.com/wutiange/log-listener-plugin.git"
|
10
10
|
},
|
@@ -39,9 +39,11 @@
|
|
39
39
|
"files": [
|
40
40
|
"src",
|
41
41
|
"package.json",
|
42
|
-
"packages",
|
43
42
|
"README.md",
|
44
43
|
"LICENSE",
|
45
|
-
"dist"
|
44
|
+
"dist",
|
45
|
+
"console.ts",
|
46
|
+
"fetch.ts",
|
47
|
+
"index.ts"
|
46
48
|
]
|
47
49
|
}
|
package/dist/server.d.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
declare class Server {
|
2
|
-
private baseUrl;
|
3
|
-
private port;
|
4
|
-
constructor(url: string);
|
5
|
-
private send;
|
6
|
-
updateUrl(url: string): void;
|
7
|
-
log(data: Record<string, any>): Promise<string>;
|
8
|
-
network(data: Record<string, any>): Promise<string>;
|
9
|
-
}
|
10
|
-
export default Server;
|
package/dist/server.js
DELETED
@@ -1,45 +0,0 @@
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
class Server {
|
13
|
-
constructor(url) {
|
14
|
-
this.baseUrl = '';
|
15
|
-
this.port = 27751;
|
16
|
-
this.updateUrl(url);
|
17
|
-
}
|
18
|
-
send(path, data) {
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
20
|
-
const result = yield fetch(`${this.baseUrl}:${this.port}/${path}`, {
|
21
|
-
method: 'POST',
|
22
|
-
headers: {
|
23
|
-
'Content-Type': 'application/json;charset=utf-8'
|
24
|
-
},
|
25
|
-
body: JSON.stringify(data)
|
26
|
-
});
|
27
|
-
return result.text();
|
28
|
-
});
|
29
|
-
}
|
30
|
-
updateUrl(url) {
|
31
|
-
this.baseUrl = url;
|
32
|
-
}
|
33
|
-
log(data) {
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
35
|
-
return this.send("log", data);
|
36
|
-
});
|
37
|
-
}
|
38
|
-
network(data) {
|
39
|
-
return __awaiter(this, void 0, void 0, function* () {
|
40
|
-
return this.send("network", data);
|
41
|
-
});
|
42
|
-
}
|
43
|
-
}
|
44
|
-
exports.default = Server;
|
45
|
-
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,MAAM,MAAM;IAGV,YAAY,GAAW;QAFf,YAAO,GAAG,EAAE,CAAC;QACb,SAAI,GAAG,KAAK,CAAA;QAElB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACrB,CAAC;IAEa,IAAI,CAAC,IAAY,EAAE,IAAyB;;YACxD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE;gBACjE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,cAAc,EAAE,gCAAgC;iBACjD;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;aAC3B,CAAC,CAAA;YACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;QACtB,CAAC;KAAA;IAED,SAAS,CAAC,GAAW;QACnB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;IACpB,CAAC;IAEK,GAAG,CAAC,IAAyB;;YACjC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAC/B,CAAC;KAAA;IAEK,OAAO,CAAC,IAAyB;;YACrC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;QACnC,CAAC;KAAA;CACF;AAED,kBAAe,MAAM,CAAA"}
|