@wutiange/log-listener-plugin 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ declare class Logger {
2
+ private server;
3
+ private baseData;
4
+ setBaseUrl(url: string): void;
5
+ setBaseData(data: Record<string, any>): void;
6
+ private throwNotSetBaseUrl;
7
+ private throwNotSetBaseData;
8
+ private _log;
9
+ log(...data: any[]): void;
10
+ warn(...data: any[]): void;
11
+ error(...data: any[]): void;
12
+ req(input: RequestInfo | URL, init?: RequestInit): Promise<string>;
13
+ res(id: number, response?: Response, isTimeout?: boolean): Promise<string>;
14
+ }
15
+ declare const _default: Logger;
16
+ export default _default;
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ class Logger {
62
62
  res(id, response, isTimeout = false) {
63
63
  return __awaiter(this, void 0, void 0, function* () {
64
64
  const body = yield response.text();
65
- return this.server.network(Object.assign(Object.assign({}, this.baseData), { headers: response === null || response === void 0 ? void 0 : response.headers, body, requestId: id, statusCode: response === null || response === void 0 ? void 0 : response.status, endTime: Date.now(), isTimeout }));
65
+ return this.server.network(Object.assign(Object.assign({}, this.baseData), { headers: response === null || response === void 0 ? void 0 : response.headers, body, requestId: Number(id), statusCode: response === null || response === void 0 ? void 0 : response.status, endTime: Date.now(), isTimeout, isResponseError: id === undefined || id === null }));
66
66
  });
67
67
  }
68
68
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sDAA6B;AAG7B,MAAM,MAAM;IAAZ;QAEU,WAAM,GAAkB,IAAI,CAAA;IA2EtC,CAAC;IAxEC,UAAU,CAAC,GAAW;QACpB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAC5B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,GAAG,CAAC,CAAA;Q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IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,mCAAI,KAAK,EAC7B,OAAO,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,EACtB,IAAI,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,EAChB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,IACtB,CAAA;;KACH;IAEK,GAAG,CAAC,EAAU,EAAE,QAAmB,EAAE,SAAS,GAAG,KAAK;;YAC1D,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;YAClC,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,iCACrB,IAAI,CAAC,QAAQ,KAChB,OAAO,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,OAAO,EAC1B,IAAI,EACJ,SAAS,EAAE,MAAM,CAAC,EAAE,CAAC,EACrB,UAAU,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,EAC5B,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,EACnB,SAAS,EACT,eAAe,EAAE,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,IAAI,IAChD,CAAA;QACJ,CAAC;KAAA;CACF;AAGD,kBAAe,IAAI,MAAM,EAAE,CAAA"}
@@ -0,0 +1,10 @@
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 ADDED
@@ -0,0 +1,45 @@
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
@@ -0,0 +1 @@
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wutiange/log-listener-plugin",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "这是log-record的插件,如果需要使用这个日志监听,那么就需要把这个插件安装到项目中",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -10,8 +10,7 @@
10
10
  "private": false,
11
11
  "scripts": {
12
12
  "build": "tsc",
13
- "dev": "ts-node ./src/index.ts",
14
- "publish": "npm run build"
13
+ "dev": "ts-node ./src/index.ts"
15
14
  },
16
15
  "devDependencies": {
17
16
  "ts-node": "^10.9.2",
package/src/index.ts CHANGED
@@ -71,10 +71,11 @@ class Logger {
71
71
  ...this.baseData,
72
72
  headers: response?.headers,
73
73
  body,
74
- requestId: id,
74
+ requestId: Number(id),
75
75
  statusCode: response?.status,
76
76
  endTime: Date.now(),
77
77
  isTimeout,
78
+ isResponseError: id === undefined || id === null
78
79
  })
79
80
  }
80
81
  }