@wutiange/log-listener-plugin 2.0.1 → 2.0.2-alpha.2
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/README.md +166 -163
- package/dist/index.cjs.js +7 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +34 -2
- package/dist/index.esm.js +5 -0
- package/dist/index.esm.js.map +1 -0
- package/index.ts +3 -3
- package/package.json +52 -59
- package/src/HTTPInterceptor.ts +340 -340
- package/src/Server.ts +174 -178
- package/src/__mocks__/react-native/Libraries/Blob/FileReader.js +44 -44
- package/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +39 -39
- package/src/__tests__/HTTPInterceptor.test.ts +322 -322
- package/src/__tests__/Server.test.ts +150 -150
- package/src/__tests__/utils.test.ts +114 -114
- package/src/common.ts +57 -57
- package/src/logPlugin.ts +238 -231
- package/src/logger.ts +15 -15
- package/src/utils.ts +135 -112
- package/LICENSE +0 -201
- package/dist/console.d.ts +0 -1
- package/dist/console.js +0 -20
- package/dist/console.js.map +0 -1
- package/dist/fetch.d.ts +0 -1
- package/dist/fetch.js +0 -48
- package/dist/fetch.js.map +0 -1
- package/dist/index.js +0 -8
- package/dist/index.js.map +0 -1
- package/dist/src/HTTPInterceptor.d.ts +0 -50
- package/dist/src/HTTPInterceptor.js +0 -227
- package/dist/src/HTTPInterceptor.js.map +0 -1
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.d.ts +0 -14
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js +0 -41
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js.map +0 -1
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.d.ts +0 -17
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +0 -34
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js.map +0 -1
- package/dist/src/__tests__/HTTPInterceptor.test.d.ts +0 -9
- package/dist/src/__tests__/HTTPInterceptor.test.js +0 -281
- package/dist/src/__tests__/HTTPInterceptor.test.js.map +0 -1
- package/dist/src/__tests__/Server.test.d.ts +0 -1
- package/dist/src/__tests__/Server.test.js +0 -116
- package/dist/src/__tests__/Server.test.js.map +0 -1
- package/dist/src/__tests__/console.test.d.ts +0 -1
- package/dist/src/__tests__/console.test.js +0 -29
- package/dist/src/__tests__/console.test.js.map +0 -1
- package/dist/src/__tests__/utils.test.d.ts +0 -1
- package/dist/src/__tests__/utils.test.js +0 -112
- package/dist/src/__tests__/utils.test.js.map +0 -1
- package/dist/src/common.d.ts +0 -14
- package/dist/src/common.js +0 -54
- package/dist/src/common.js.map +0 -1
- package/dist/src/logPlugin.d.ts +0 -35
- package/dist/src/logPlugin.js +0 -188
- package/dist/src/logPlugin.js.map +0 -1
- package/dist/src/logger.d.ts +0 -6
- package/dist/src/logger.js +0 -16
- package/dist/src/logger.js.map +0 -1
- package/dist/src/server.d.ts +0 -21
- package/dist/src/server.js +0 -178
- package/dist/src/server.js.map +0 -1
- package/dist/src/utils.d.ts +0 -6
- package/dist/src/utils.js +0 -106
- package/dist/src/utils.js.map +0 -1
- package/tsconfig.json +0 -27
package/README.md
CHANGED
@@ -1,163 +1,166 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
[](https://www.npmjs.com/package/@wutiange/log-listener-plugin?activeTab=dependencies)
|
5
|
+
[](https://www.npmjs.com/package/@wutiange/log-listener-plugin)
|
6
|
+
[](https://www.npmjs.com/package/@wutiange/log-listener-plugin)
|
7
|
+
[](./LICENSE)
|
8
|
+
|
9
|
+
[中文](../../README.md) | English
|
10
|
+
|
11
|
+
To properly use the [Log Record](https://github.com/wutiange/log-record) client for log collection and troubleshooting, you need to install this plugin in your project.
|
12
|
+
|
13
|
+
## 1. Installation
|
14
|
+
|
15
|
+
Install using npm
|
16
|
+
|
17
|
+
```bash
|
18
|
+
npm install @wutiange/log-listener-plugin
|
19
|
+
```
|
20
|
+
|
21
|
+
Install using yarn
|
22
|
+
|
23
|
+
```bash
|
24
|
+
yarn add @wutiange/log-listener-plugin
|
25
|
+
```
|
26
|
+
**Since the logging system uses HTTP, the project needs to be configured to support HTTP for proper operation.**
|
27
|
+
|
28
|
+
## 2. Usage
|
29
|
+
|
30
|
+
Call the following code where you need to start recording logs.
|
31
|
+
|
32
|
+
### 2.1 Usage Based on Auto-Discovery
|
33
|
+
|
34
|
+
First install react-native-zeroconf, which is used to discover available logging systems in the local network.
|
35
|
+
|
36
|
+
```bash
|
37
|
+
yarn add react-native-zeroconf
|
38
|
+
# or
|
39
|
+
npm install react-native-zeroconf
|
40
|
+
```
|
41
|
+
|
42
|
+
For detailed installation steps, please visit: [react-native-zeroconf](https://www.npmjs.com/package/react-native-zeroconf). Don't ignore this line as there are necessary steps to follow. I've also copied these steps below to prevent oversight.
|
43
|
+
|
44
|
+
For Android please ensure your manifest is requesting all necessary permissions.
|
45
|
+
|
46
|
+
```xml
|
47
|
+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
48
|
+
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
49
|
+
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
50
|
+
```
|
51
|
+
|
52
|
+
IOS 14 requires you to specify the services you want to scan for and a description for what you're using them.
|
53
|
+
|
54
|
+
In your `info.plist` add the following strings:
|
55
|
+
|
56
|
+
```plist
|
57
|
+
<key>NSBonjourServices</key>
|
58
|
+
<array>
|
59
|
+
<string>_http._tcp</string>
|
60
|
+
</array>
|
61
|
+
<key>NSLocalNetworkUsageDescription</key>
|
62
|
+
<string>Access nearby Log Records to view logs</string>
|
63
|
+
```
|
64
|
+
|
65
|
+
Then find a suitable place in your project, typically in App.js, to make the call.
|
66
|
+
|
67
|
+
```ts
|
68
|
+
import logger from '@wutiange/log-listener-plugin';
|
69
|
+
// Start log recording
|
70
|
+
logger.config({isAuto: true});
|
71
|
+
```
|
72
|
+
|
73
|
+
### 2.2 Usage Based on Manual Configuration
|
74
|
+
|
75
|
+
```ts
|
76
|
+
import logger from '@wutiange/log-listener-plugin';
|
77
|
+
// Fill in the log server address. If you use auto-discovery, this step can be skipped
|
78
|
+
logger.config({isAuto: true, testUrl: 'http://127.0.0.1'});
|
79
|
+
```
|
80
|
+
|
81
|
+
### 2.3 Setting Basic Data
|
82
|
+
|
83
|
+
Set basic data, typically obtained from react-native-device-info. If you don't have specific requirements, you can skip this call as the basic data will be automatically retrieved from react-native-device-info if installed. This basic data is used for filtering and is not mandatory.
|
84
|
+
|
85
|
+
```ts
|
86
|
+
logger.config({
|
87
|
+
baseData: {
|
88
|
+
Brand: DeviceInfo.getBrand(),
|
89
|
+
Model: DeviceInfo.getModel(),
|
90
|
+
AppVersion: DeviceInfo.getVersion(),
|
91
|
+
Carrier: DeviceInfo.getCarrierSync(),
|
92
|
+
Manufacturer: DeviceInfo.getManufacturerSync(),
|
93
|
+
SystemName: DeviceInfo.getSystemName(),
|
94
|
+
}
|
95
|
+
});
|
96
|
+
```
|
97
|
+
|
98
|
+
### 2.4 Individual Recording and Stopping All Records
|
99
|
+
|
100
|
+
Try to avoid using the following APIs as they are unnecessary. This data will only be saved to the logging system you have open, so collect whatever is available to facilitate troubleshooting.
|
101
|
+
|
102
|
+
```ts
|
103
|
+
// Only capture logs
|
104
|
+
logger.startRecordLog();
|
105
|
+
// Only capture network logs
|
106
|
+
logger.startRecordNetwork();
|
107
|
+
|
108
|
+
// Stop log recording, will stop both logs and network
|
109
|
+
logger.unAuto();
|
110
|
+
```
|
111
|
+
|
112
|
+
### 2.5 Other Usage Instructions
|
113
|
+
|
114
|
+
If you want to remember the previously saved IP address even after killing the app, consider installing:
|
115
|
+
|
116
|
+
```bash
|
117
|
+
yarn add @react-native-async-storage/async-storage
|
118
|
+
```
|
119
|
+
|
120
|
+
If you have other storage installed locally, you can set it manually:
|
121
|
+
|
122
|
+
```ts
|
123
|
+
logger.config({
|
124
|
+
storage: // Your storage or custom implementation, as long as it follows the getItem and setItem interface specifications
|
125
|
+
})
|
126
|
+
```
|
127
|
+
|
128
|
+
Now all configuration-related items are placed in config to simplify configuration. Each configuration item is optional:
|
129
|
+
|
130
|
+
```ts
|
131
|
+
type Options = {
|
132
|
+
/**
|
133
|
+
* storage is used to store the url of the configured logging system
|
134
|
+
* @default @react-native-async-storage/async-storage
|
135
|
+
*/
|
136
|
+
storage?: Storage
|
137
|
+
/**
|
138
|
+
* Set the upload log timeout in milliseconds
|
139
|
+
* @default 3000
|
140
|
+
*/
|
141
|
+
timeout?: number
|
142
|
+
/**
|
143
|
+
* Logging system url
|
144
|
+
*/
|
145
|
+
testUrl?: string
|
146
|
+
/**
|
147
|
+
* Whether to automatically start log recording
|
148
|
+
* @default false
|
149
|
+
*/
|
150
|
+
isAuto?: boolean
|
151
|
+
/**
|
152
|
+
* Set basic data for the logging system, this data will be automatically added to each log
|
153
|
+
*/
|
154
|
+
baseData?: Record<string, any>
|
155
|
+
}
|
156
|
+
```
|
157
|
+
|
158
|
+
This is the description of each config item.
|
159
|
+
|
160
|
+
## 3. Other Important Notes
|
161
|
+
|
162
|
+
1. If you're using auto-discovery mode, ensure your phone and Log Record client are on the same local network.
|
163
|
+
2. When configuring baseUrl, you must enter the address of [Log Record](https://github.com/wutiange/log-record). In other words, use the IP address of the computer where you opened the Log Record client. The app integrated with this plugin must be on the same local network as the Log Record client.
|
164
|
+
3. If you don't know the logging system's IP, you can find it in the Log Record client under `Settings > Connection Instructions (requires version > 1.0.9)`, as shown in the image below:
|
165
|
+
|
166
|
+

|
@@ -0,0 +1,7 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const logPlugin_1 = tslib_1.__importDefault(require("./src/logPlugin"));
|
6
|
+
exports.default = logPlugin_1.default;
|
7
|
+
//# sourceMappingURL=index.cjs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../../index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAAA,MAAwC,WAAA,GAAA,OAAA,CAAA,eAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,CAAA;AAExC,OAAA,CAAA,OAAA,GAAe,mBAAS;;"}
|
package/dist/index.d.ts
CHANGED
@@ -1,2 +1,34 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
type Options = {
|
2
|
+
storage?: Storage;
|
3
|
+
timeout?: number;
|
4
|
+
testUrl?: string;
|
5
|
+
isAuto?: boolean;
|
6
|
+
baseData?: Record<string, any>;
|
7
|
+
};
|
8
|
+
declare class LogPlugin {
|
9
|
+
private server;
|
10
|
+
private timeout;
|
11
|
+
private isAuto;
|
12
|
+
private storage;
|
13
|
+
constructor();
|
14
|
+
private init;
|
15
|
+
config: ({ storage, timeout, testUrl, isAuto, baseData }: Options) => void;
|
16
|
+
auto: () => void;
|
17
|
+
unAuto: () => void;
|
18
|
+
startRecordLog: () => void;
|
19
|
+
stopRecordLog: () => void;
|
20
|
+
private handleIgnoredUrls;
|
21
|
+
startRecordNetwork: () => void;
|
22
|
+
setBaseUrl: (url?: string) => void;
|
23
|
+
setTimeout: (timeout: number) => void;
|
24
|
+
getTimeout: () => number | null;
|
25
|
+
setBaseData: (data?: Record<string, any>) => void;
|
26
|
+
private _log;
|
27
|
+
tag: (tag: string, ...data: any[]) => void;
|
28
|
+
log: (...data: any[]) => void;
|
29
|
+
warn: (...data: any[]) => void;
|
30
|
+
error: (...data: any[]) => void;
|
31
|
+
}
|
32
|
+
declare const logPlugin: LogPlugin;
|
33
|
+
|
34
|
+
export { logPlugin as default };
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../../index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAAA,MAAwC,WAAA,GAAA,OAAA,CAAA,eAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,CAAA;AAExC,OAAA,CAAA,OAAA,GAAe,mBAAS"}
|
package/index.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import logPlugin from './src/logPlugin';
|
2
|
-
|
3
|
-
export default logPlugin;
|
1
|
+
import logPlugin from './src/logPlugin';
|
2
|
+
|
3
|
+
export default logPlugin;
|
package/package.json
CHANGED
@@ -1,59 +1,52 @@
|
|
1
|
-
{
|
2
|
-
"name": "@wutiange/log-listener-plugin",
|
3
|
-
"version": "2.0.
|
4
|
-
"description": "log-record 客户端对应的的插件\r\nLog-record client corresponding plugin",
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
|
11
|
-
"
|
12
|
-
|
13
|
-
|
14
|
-
"
|
15
|
-
"
|
16
|
-
|
17
|
-
"
|
18
|
-
"
|
19
|
-
"
|
20
|
-
|
21
|
-
|
22
|
-
"scripts": {
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
"@types/
|
32
|
-
"@types/
|
33
|
-
|
34
|
-
|
35
|
-
"
|
36
|
-
"
|
37
|
-
"
|
38
|
-
"
|
39
|
-
},
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
"
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
"
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
"tsconfig.json"
|
54
|
-
],
|
55
|
-
"dependencies": {
|
56
|
-
"crypto-js": "^4.2.0",
|
57
|
-
"url-parse": "^1.5.10"
|
58
|
-
}
|
59
|
-
}
|
1
|
+
{
|
2
|
+
"name": "@wutiange/log-listener-plugin",
|
3
|
+
"version": "2.0.2-alpha.2",
|
4
|
+
"description": "log-record 客户端对应的的插件\r\nLog-record client corresponding plugin",
|
5
|
+
"source": "index.ts",
|
6
|
+
"react-native": "index.ts",
|
7
|
+
"main": "dist/index.cjs.js",
|
8
|
+
"module": "dist/index.esm.js",
|
9
|
+
"types": "dist/index.d.ts",
|
10
|
+
"repository": {
|
11
|
+
"type": "git",
|
12
|
+
"url": "https://github.com/wutiange/log-listener-plugin.git"
|
13
|
+
},
|
14
|
+
"author": "wutiange <wutiange20@qq,com>",
|
15
|
+
"license": "MIT",
|
16
|
+
"keywords": [
|
17
|
+
"react-native",
|
18
|
+
"log",
|
19
|
+
"debugger",
|
20
|
+
"charles"
|
21
|
+
],
|
22
|
+
"scripts": {
|
23
|
+
"publish-alpha": "npm publish --access public --tag alpha",
|
24
|
+
"prepublishOnly": "npm run build",
|
25
|
+
"test": "jest",
|
26
|
+
"build": "yarn clean && yarn test && rollup -c",
|
27
|
+
"dev": "rollup -c -w",
|
28
|
+
"clean": "rimraf dist"
|
29
|
+
},
|
30
|
+
"devDependencies": {
|
31
|
+
"@types/react-native-zeroconf": "^0.13.1",
|
32
|
+
"@types/url-parse": "^1.4.11"
|
33
|
+
},
|
34
|
+
"peerDependencies": {
|
35
|
+
"@react-native-async-storage/async-storage": "*",
|
36
|
+
"react-native": "*",
|
37
|
+
"react-native-device-info": "^14.0.0",
|
38
|
+
"react-native-zeroconf": "^0.13.8"
|
39
|
+
},
|
40
|
+
"files": [
|
41
|
+
"package.json",
|
42
|
+
"README.md",
|
43
|
+
"LICENSE",
|
44
|
+
"dist",
|
45
|
+
"src",
|
46
|
+
"index.ts"
|
47
|
+
],
|
48
|
+
"dependencies": {
|
49
|
+
"url-parse": "^1.5.10"
|
50
|
+
},
|
51
|
+
"packageManager": "yarn@4.5.3"
|
52
|
+
}
|