@zxhy-npm/send-sls-logger 1.0.3 → 1.1.1
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/lib/index.js +4 -9
- package/lib/init.d.ts +1 -0
- package/lib/init.js +8 -6
- package/lib/mini.js +4 -9
- package/lib/trace.d.ts +1 -0
- package/lib/trace.js +41 -0
- package/package.json +3 -7
- package/readme.md +2 -0
package/lib/index.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const web_track_browser_1 = __importDefault(require("@aliyun-sls/web-track-browser"));
|
|
7
|
-
const init_1 = __importDefault(require("./init"));
|
|
8
|
-
const SLSLog = (config) => new init_1.default(web_track_browser_1.default, config);
|
|
9
|
-
exports.default = SLSLog;
|
|
1
|
+
import SlsTracker from "@aliyun-sls/web-track-browser";
|
|
2
|
+
import DefaultLog from "./init";
|
|
3
|
+
const SLSLog = (config) => new DefaultLog(SlsTracker, config);
|
|
4
|
+
export default SLSLog;
|
package/lib/init.d.ts
CHANGED
package/lib/init.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
const getType = (val) => {
|
|
4
2
|
return Object.prototype.toString.call(val).toLocaleLowerCase().slice(8, -1);
|
|
5
3
|
};
|
|
@@ -25,15 +23,19 @@ class DefaultLog {
|
|
|
25
23
|
}
|
|
26
24
|
/** 初始化日志配置,可以多次调用 */
|
|
27
25
|
init(config) {
|
|
28
|
-
const { defaultData = {}, defaultExclude = [], options, strMaxLength = defaultMaxLength, debug: defaultDebug
|
|
29
|
-
|
|
26
|
+
const { defaultData = {}, defaultExclude = [], options, strMaxLength = defaultMaxLength, debug: defaultDebug, userFormatResult: defaultUserFormatResult = (_) => _, } = config;
|
|
27
|
+
if (defaultDebug !== undefined) {
|
|
28
|
+
this.debug = defaultDebug;
|
|
29
|
+
}
|
|
30
30
|
this.userFormatResult = defaultUserFormatResult;
|
|
31
31
|
Object.assign(this.defaultLogData, defaultData);
|
|
32
32
|
Object.assign(this.opts, options);
|
|
33
33
|
if (options?.host && options.logstore && options.project) {
|
|
34
34
|
this.tracker = new this.Tracker(options);
|
|
35
35
|
}
|
|
36
|
-
this.maxLength
|
|
36
|
+
if (this.maxLength === defaultMaxLength && strMaxLength !== defaultMaxLength) {
|
|
37
|
+
this.maxLength = strMaxLength;
|
|
38
|
+
}
|
|
37
39
|
this.exclude.push(...defaultExclude);
|
|
38
40
|
}
|
|
39
41
|
formatDataMaxLength(data) {
|
|
@@ -126,4 +128,4 @@ class DefaultLog {
|
|
|
126
128
|
log = this.send('info');
|
|
127
129
|
info = this.send('info');
|
|
128
130
|
}
|
|
129
|
-
|
|
131
|
+
export default DefaultLog;
|
package/lib/mini.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const web_track_mini_1 = __importDefault(require("@aliyun-sls/web-track-mini"));
|
|
7
|
-
const init_1 = __importDefault(require("./init"));
|
|
8
|
-
const MiniInit = (config) => new init_1.default(web_track_mini_1.default, config);
|
|
9
|
-
exports.default = MiniInit;
|
|
1
|
+
import SlsMiniTracker from "@aliyun-sls/web-track-mini";
|
|
2
|
+
import DefaultLog from "./init";
|
|
3
|
+
const MiniInit = (config) => new DefaultLog(SlsMiniTracker, config);
|
|
4
|
+
export default MiniInit;
|
package/lib/trace.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initTrace(info: (...data: any[]) => any): void;
|
package/lib/trace.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function initTrace(info) {
|
|
2
|
+
const observer = new MutationObserver(() => {
|
|
3
|
+
const modules = document.querySelectorAll('[data-module]');
|
|
4
|
+
const observer = new IntersectionObserver((entries, observer) => {
|
|
5
|
+
entries.forEach((entry) => {
|
|
6
|
+
if (entry.isIntersecting) {
|
|
7
|
+
const module = entry.target;
|
|
8
|
+
const moduleName = module.dataset.module;
|
|
9
|
+
moduleName && info({
|
|
10
|
+
moduleName,
|
|
11
|
+
entryType: 'load',
|
|
12
|
+
});
|
|
13
|
+
observer.unobserve(module);
|
|
14
|
+
delete module.dataset.module;
|
|
15
|
+
}
|
|
16
|
+
}, {
|
|
17
|
+
root: null,
|
|
18
|
+
threshold: 0.1,
|
|
19
|
+
rootMargin: '0px',
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
modules.forEach((module) => observer.observe(module));
|
|
23
|
+
});
|
|
24
|
+
observer.observe(document.body, {
|
|
25
|
+
childList: true,
|
|
26
|
+
subtree: true,
|
|
27
|
+
});
|
|
28
|
+
const clickHandler = (event) => {
|
|
29
|
+
const target = event.target;
|
|
30
|
+
const closestElement = target.closest('[data-click]');
|
|
31
|
+
if (closestElement) {
|
|
32
|
+
const moduleName = closestElement.dataset.click || '';
|
|
33
|
+
moduleName && info({
|
|
34
|
+
moduleName,
|
|
35
|
+
entryType: 'click',
|
|
36
|
+
});
|
|
37
|
+
delete target.dataset.click;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
window.addEventListener('click', clickHandler);
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zxhy-npm/send-sls-logger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "阿里云sls的logger发送",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf lib && tsc"
|
|
7
7
|
},
|
|
8
8
|
"files": [
|
|
9
|
-
"lib"
|
|
9
|
+
"lib/**/*"
|
|
10
10
|
],
|
|
11
11
|
"main": "lib/index.js",
|
|
12
12
|
"types": "lib/index.d.ts",
|
|
13
|
-
"exports": {
|
|
14
|
-
".": "./lib/index.js",
|
|
15
|
-
"./mini": "./lib/mini.js"
|
|
16
|
-
},
|
|
17
13
|
"keywords": [
|
|
18
14
|
"logger",
|
|
19
15
|
"sls"
|
|
@@ -31,4 +27,4 @@
|
|
|
31
27
|
"@aliyun-sls/web-track-browser": "^0.0.3",
|
|
32
28
|
"@aliyun-sls/web-track-mini": "^0.0.2"
|
|
33
29
|
}
|
|
34
|
-
}
|
|
30
|
+
}
|
package/readme.md
CHANGED