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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import { WebTrackerBrowserOptions } from "@aliyun-sls/web-track-browser";
2
2
 
3
3
  interface StringObject {
4
- [name: string]: string;
4
+ [name: string]: string | Function;
5
5
  }
6
6
 
7
7
  interface Options extends WebTrackerBrowserOptions {
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
- return { ...result, data };
49
+ Object.assign(result, { data });
39
50
  } else if (typeof data === "object") {
40
- return { ...result, ...data };
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
- const isExcludeMsg = Object.keys(data).find((key) => {
54
- return exclude.find((i) => new RegExp(i, "g").test(data[key]));
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(data);
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-browser";
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "send-sls-logger",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "阿里云sls的logger发送",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"