send-sls-logger 0.0.29 → 0.0.31
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.d.ts +1 -1
- package/lib/init.js +24 -11
- package/lib/mini.d.ts +2 -2
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/init.js
CHANGED
|
@@ -29,17 +29,28 @@ const formatDataMaxLength = (data) => {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
const formatFunctionObj = (data) => {
|
|
33
|
+
if (getType(data) === "object") {
|
|
34
|
+
return Object.keys(data).reduce((curr, key) => {
|
|
35
|
+
curr[key] = formatFunctionObj(data[key]);
|
|
36
|
+
return curr;
|
|
37
|
+
}, {});
|
|
38
|
+
} else if (getType(data) === "array") {
|
|
39
|
+
return data.map((i) => formatFunctionObj(i));
|
|
40
|
+
} else if (getType(data) === "function") {
|
|
41
|
+
return data();
|
|
42
|
+
} else {
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
32
46
|
const formatLogData = (data, type = "log") => {
|
|
33
|
-
const result = {
|
|
34
|
-
type,
|
|
35
|
-
...defaultLogData,
|
|
36
|
-
};
|
|
47
|
+
const result = { ...defaultLogData, type };
|
|
37
48
|
if (typeof data === "string") {
|
|
38
|
-
|
|
49
|
+
Object.assign(result, { data });
|
|
39
50
|
} else if (typeof data === "object") {
|
|
40
|
-
|
|
51
|
+
Object.assign(result, data);
|
|
41
52
|
}
|
|
42
|
-
return result;
|
|
53
|
+
return formatFunctionObj(result);
|
|
43
54
|
};
|
|
44
55
|
|
|
45
56
|
const send = (type) => {
|
|
@@ -50,14 +61,16 @@ const send = (type) => {
|
|
|
50
61
|
} else if (typeof err === "object") {
|
|
51
62
|
data = { ...err };
|
|
52
63
|
}
|
|
53
|
-
|
|
54
|
-
|
|
64
|
+
|
|
65
|
+
const result = formatLogData(data, type);
|
|
66
|
+
const isExcludeMsg = Object.keys(result).find((key) => {
|
|
67
|
+
return exclude.find((i) => new RegExp(i, "g").test(result[key]));
|
|
55
68
|
});
|
|
69
|
+
|
|
56
70
|
if (isExcludeMsg) {
|
|
57
|
-
console.log(
|
|
71
|
+
console.log(`logger ${type}`, result);
|
|
58
72
|
return;
|
|
59
73
|
}
|
|
60
|
-
const result = formatLogData(data, type);
|
|
61
74
|
if (!opts.host || !opts.project || !opts.logstore) {
|
|
62
75
|
return console.warn("日志初始化需要配置options", result);
|
|
63
76
|
}
|
package/lib/mini.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { WebTrackerBrowserOptions } from "@aliyun-sls/web-track-
|
|
1
|
+
import { WebTrackerBrowserOptions } from "@aliyun-sls/web-track-mini";
|
|
2
2
|
interface StringObject {
|
|
3
|
-
[name: string]: string;
|
|
3
|
+
[name: string]: string | Function;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
interface Options extends WebTrackerBrowserOptions {
|