@wutiange/log-listener-plugin 1.2.0 → 1.3.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/console.js +14 -15
- package/dist/console.js.map +1 -1
- package/dist/fetch.js +28 -28
- package/dist/fetch.js.map +1 -1
- package/dist/index.d.ts +2 -23
- package/dist/index.js +2 -117
- package/dist/index.js.map +1 -1
- package/dist/packages/network-logger/Logger.d.ts +28 -0
- package/dist/packages/network-logger/Logger.js +192 -0
- package/dist/packages/network-logger/Logger.js.map +1 -0
- package/dist/packages/network-logger/NetworkRequestInfo.d.ts +36 -0
- package/dist/packages/network-logger/NetworkRequestInfo.js +129 -0
- package/dist/packages/network-logger/NetworkRequestInfo.js.map +1 -0
- package/dist/packages/network-logger/constant.d.ts +2 -0
- package/dist/packages/network-logger/constant.js +6 -0
- package/dist/packages/network-logger/constant.js.map +1 -0
- package/dist/packages/network-logger/types.d.ts +14 -0
- package/dist/packages/network-logger/types.js +3 -0
- package/dist/packages/network-logger/types.js.map +1 -0
- package/dist/packages/network-logger/utils/debounce.d.ts +2 -0
- package/dist/packages/network-logger/utils/debounce.js +20 -0
- package/dist/packages/network-logger/utils/debounce.js.map +1 -0
- package/dist/packages/network-logger/utils/extractHost.d.ts +2 -0
- package/dist/packages/network-logger/utils/extractHost.js +9 -0
- package/dist/packages/network-logger/utils/extractHost.js.map +1 -0
- package/dist/packages/network-logger/utils/fromEntries.d.ts +2 -0
- package/dist/packages/network-logger/utils/fromEntries.js +8 -0
- package/dist/packages/network-logger/utils/fromEntries.js.map +1 -0
- package/dist/packages/network-logger/utils/logger.d.ts +1 -0
- package/dist/packages/network-logger/utils/logger.js +6 -0
- package/dist/packages/network-logger/utils/logger.js.map +1 -0
- package/dist/src/CompatibilityManager.d.ts +27 -0
- package/dist/src/CompatibilityManager.js +74 -0
- package/dist/src/CompatibilityManager.js.map +1 -0
- package/dist/src/__tests__/console.test.d.ts +1 -0
- package/dist/{__tests__ → src/__tests__}/console.test.js +2 -2
- package/dist/src/__tests__/console.test.js.map +1 -0
- package/dist/src/common.js.map +1 -0
- package/dist/src/console.d.ts +1 -0
- package/dist/src/console.js +20 -0
- package/dist/src/console.js.map +1 -0
- package/dist/src/fetch.d.ts +1 -0
- package/dist/src/fetch.js +48 -0
- package/dist/src/fetch.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +8 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/logPlugin.d.ts +32 -0
- package/dist/src/logPlugin.js +187 -0
- package/dist/src/logPlugin.js.map +1 -0
- package/dist/{server.d.ts → src/server.d.ts} +1 -1
- package/dist/{server.js → src/server.js} +14 -8
- package/dist/src/server.js.map +1 -0
- package/dist/src/utils.d.ts +3 -0
- package/dist/src/utils.js +38 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +13 -5
- package/packages/network-logger/Logger.ts +274 -0
- package/packages/network-logger/NetworkRequestInfo.ts +133 -0
- package/packages/network-logger/constant.ts +3 -0
- package/packages/network-logger/types.ts +36 -0
- package/packages/network-logger/utils/debounce.ts +21 -0
- package/packages/network-logger/utils/extractHost.ts +7 -0
- package/packages/network-logger/utils/fromEntries.ts +7 -0
- package/packages/network-logger/utils/logger.ts +2 -0
- package/src/CompatibilityManager.ts +64 -0
- package/src/__tests__/console.test.ts +2 -2
- package/src/common.ts +2 -3
- package/src/logPlugin.ts +229 -0
- package/src/server.ts +28 -23
- package/src/utils.ts +38 -0
- package/dist/__tests__/console.test.d.ts +0 -1
- package/dist/__tests__/console.test.js.map +0 -1
- package/dist/common.js.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/utils.d.ts +0 -1
- package/dist/utils.js +0 -14
- package/dist/utils.js.map +0 -1
- package/src/console.ts +0 -19
- package/src/fetch.ts +0 -35
- package/src/index.ts +0 -131
- /package/dist/{common.d.ts → src/common.d.ts} +0 -0
- /package/dist/{common.js → src/common.js} +0 -0
package/dist/utils.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.sleep = void 0;
|
4
|
-
function sleep(ms, isReject = false) {
|
5
|
-
return new Promise((resolve, reject) => {
|
6
|
-
setTimeout(isReject ? () => reject({
|
7
|
-
code: 11001,
|
8
|
-
key: '@wutiange/log-listener-plugin%%timeout',
|
9
|
-
msg: 'Timeout'
|
10
|
-
}) : resolve, ms);
|
11
|
-
});
|
12
|
-
}
|
13
|
-
exports.sleep = sleep;
|
14
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK,CAAC,EAAU,EAAE,WAAoB,KAAK;IACzD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;YACjC,IAAI,EAAE,KAAK;YACX,GAAG,EAAE,wCAAwC;YAC7C,GAAG,EAAE,SAAS;SACf,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC;AARD,sBAQC"}
|
package/src/console.ts
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
import logger from './index'
|
2
|
-
|
3
|
-
import('./common.js').then(common => {
|
4
|
-
console.log = (...data: any[]) => {
|
5
|
-
logger.log(...data)
|
6
|
-
common.log(...data)
|
7
|
-
}
|
8
|
-
|
9
|
-
console.warn = (...data: any[]) => {
|
10
|
-
logger.warn(...data)
|
11
|
-
common.warn(...data)
|
12
|
-
}
|
13
|
-
|
14
|
-
console.error = (...data: any[]) => {
|
15
|
-
logger.error(...data)
|
16
|
-
common.error(...data)
|
17
|
-
}
|
18
|
-
})
|
19
|
-
|
package/src/fetch.ts
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
import logger from './index'
|
2
|
-
import { sleep } from './utils'
|
3
|
-
|
4
|
-
import('./common.js').then(common => {
|
5
|
-
// @ts-ignore
|
6
|
-
global.fetch = async (input: RequestInfo | URL, init?: RequestInit) => {
|
7
|
-
const uniqueId = (Date.now() + Math.random()).toString(16)
|
8
|
-
logger.uniqueReq(uniqueId, input, init)
|
9
|
-
let isFetchFinished = false
|
10
|
-
let isTimeout = false
|
11
|
-
if (logger.getTimeout() !== null) {
|
12
|
-
sleep(logger.getTimeout()).then(() => {
|
13
|
-
if (!isFetchFinished) {
|
14
|
-
isTimeout = true
|
15
|
-
logger.resTimeout(uniqueId)
|
16
|
-
}
|
17
|
-
})
|
18
|
-
}
|
19
|
-
|
20
|
-
try {
|
21
|
-
const response = await common.tempFetch(input, init)
|
22
|
-
isFetchFinished = true
|
23
|
-
if (response instanceof Response && !isTimeout) {
|
24
|
-
logger.uniqueRes(uniqueId, response.clone())
|
25
|
-
}
|
26
|
-
return response
|
27
|
-
} catch (error) {
|
28
|
-
isFetchFinished = true
|
29
|
-
if (!isTimeout) {
|
30
|
-
logger.resResponseError(uniqueId)
|
31
|
-
}
|
32
|
-
throw new Error(error)
|
33
|
-
}
|
34
|
-
}
|
35
|
-
})
|
package/src/index.ts
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
import Server from "./server"
|
2
|
-
|
3
|
-
|
4
|
-
class Logger {
|
5
|
-
|
6
|
-
private server: Server | null = null
|
7
|
-
private baseData: Record<string, any> = {}
|
8
|
-
private timeout: number | null = null
|
9
|
-
|
10
|
-
setBaseUrl(url: string) {
|
11
|
-
if (this.server) {
|
12
|
-
this.server.updateUrl(url)
|
13
|
-
} else {
|
14
|
-
this.server = new Server(url)
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
setTimeout(timeout: number) {
|
19
|
-
if (typeof timeout === 'number') {
|
20
|
-
this.timeout = timeout
|
21
|
-
this.server?.updateTimeout(this.timeout)
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
getTimeout() {
|
26
|
-
if (typeof this.timeout === 'number') {
|
27
|
-
return this.timeout
|
28
|
-
}
|
29
|
-
return null
|
30
|
-
}
|
31
|
-
|
32
|
-
setBaseData(data: Record<string, any> = {}) {
|
33
|
-
this.baseData = data
|
34
|
-
}
|
35
|
-
|
36
|
-
private _log(level: string, tag: string, ...data: any[]) {
|
37
|
-
const sendData = {
|
38
|
-
...this.baseData,
|
39
|
-
message: data,
|
40
|
-
tag,
|
41
|
-
level: level ?? 'log',
|
42
|
-
createTime: Date.now()
|
43
|
-
}
|
44
|
-
this.server?.log(sendData)
|
45
|
-
}
|
46
|
-
|
47
|
-
tag(tag: string, ...data: any[]) {
|
48
|
-
this._log('log', tag, ...data)
|
49
|
-
}
|
50
|
-
|
51
|
-
log(...data: any[]) {
|
52
|
-
this._log('log', 'default', ...data)
|
53
|
-
}
|
54
|
-
|
55
|
-
warn(...data: any[]) {
|
56
|
-
this._log('warn', 'default', ...data)
|
57
|
-
}
|
58
|
-
|
59
|
-
error(...data: any[]) {
|
60
|
-
this._log('error', 'default', ...data)
|
61
|
-
}
|
62
|
-
|
63
|
-
async uniqueReq(uniqueId: string, input: RequestInfo | URL, init?: RequestInit) {
|
64
|
-
let url: string | null = null
|
65
|
-
let method = init?.method ?? 'get'
|
66
|
-
let headers = init?.headers
|
67
|
-
let body = init?.body
|
68
|
-
if (input instanceof Request) {
|
69
|
-
url = input.url
|
70
|
-
method = input.method ?? 'get'
|
71
|
-
headers = input.headers
|
72
|
-
body = input.body
|
73
|
-
} else if (input instanceof URL) {
|
74
|
-
url = input.href
|
75
|
-
} else {
|
76
|
-
url = input
|
77
|
-
}
|
78
|
-
return this.server?.network({
|
79
|
-
...this.baseData,
|
80
|
-
url,
|
81
|
-
id: uniqueId,
|
82
|
-
method,
|
83
|
-
headers,
|
84
|
-
body,
|
85
|
-
createTime: Date.now(),
|
86
|
-
})
|
87
|
-
}
|
88
|
-
|
89
|
-
private async _res(uniqueId?: string, id?: number, response?: Response) {
|
90
|
-
const body = await response.text()
|
91
|
-
return this.server?.network({
|
92
|
-
...this.baseData,
|
93
|
-
headers: (response?.headers as Record<string, any>)['map'],
|
94
|
-
body,
|
95
|
-
requestId: uniqueId ?? Number(id),
|
96
|
-
statusCode: response?.status,
|
97
|
-
endTime: Date.now(),
|
98
|
-
})
|
99
|
-
}
|
100
|
-
|
101
|
-
async resTimeout(uniqueId: string) {
|
102
|
-
return this.server?.network({
|
103
|
-
...this.baseData,
|
104
|
-
isTimeout: true,
|
105
|
-
requestId: uniqueId,
|
106
|
-
})
|
107
|
-
}
|
108
|
-
|
109
|
-
async resResponseError(uniqueId: string) {
|
110
|
-
return this.server?.network({
|
111
|
-
...this.baseData,
|
112
|
-
isResponseError: true,
|
113
|
-
requestId: uniqueId,
|
114
|
-
})
|
115
|
-
}
|
116
|
-
|
117
|
-
async uniqueRes(uniqueId: string, response?: Response) {
|
118
|
-
return this._res(uniqueId, undefined, response)
|
119
|
-
}
|
120
|
-
|
121
|
-
async req(input: RequestInfo | URL, init?: RequestInit) {
|
122
|
-
return this.uniqueReq(undefined, input, init)
|
123
|
-
}
|
124
|
-
|
125
|
-
async res(id: number, response?: Response) {
|
126
|
-
return this._res(undefined, id, response)
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
|
131
|
-
export default new Logger()
|
File without changes
|
File without changes
|