@zxhy-npm/send-sls-logger 1.1.11 → 1.1.16

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/init.d.ts CHANGED
@@ -17,6 +17,7 @@ export interface InitConfig<T extends LogOptions> {
17
17
  options?: T;
18
18
  strMaxLength?: number;
19
19
  userFormatResult?: FormatResult;
20
+ formatResultToBehavior?: boolean;
20
21
  }
21
22
  export declare function deleteNullOrUndefined(obj: any): any;
22
23
  declare class DefaultLog<T extends LogOptions> {
@@ -34,6 +35,7 @@ declare class DefaultLog<T extends LogOptions> {
34
35
  private debug;
35
36
  private maxLength;
36
37
  private Tracker;
38
+ private formatResultToBehavior;
37
39
  constructor(Tracker: new (config: T) => any, config: InitConfig<T>);
38
40
  /** 初始化日志配置,可以多次调用 */
39
41
  init(config: InitConfig<T>): void;
package/lib/init.js CHANGED
@@ -39,16 +39,20 @@ class DefaultLog {
39
39
  debug = false;
40
40
  maxLength = 200;
41
41
  Tracker;
42
+ formatResultToBehavior = false;
42
43
  constructor(Tracker, config) {
43
44
  this.Tracker = Tracker;
44
45
  this.init(config);
45
46
  }
46
47
  /** 初始化日志配置,可以多次调用 */
47
48
  init(config) {
48
- const { defaultData = {}, defaultExclude = [], options, strMaxLength = defaultMaxLength, debug: defaultDebug, userFormatResult: defaultUserFormatResult = (_) => _, } = config;
49
+ const { defaultData = {}, defaultExclude = [], options, strMaxLength = defaultMaxLength, debug: defaultDebug, formatResultToBehavior, userFormatResult: defaultUserFormatResult = (_) => _, } = config;
49
50
  if (defaultDebug !== undefined) {
50
51
  this.debug = defaultDebug;
51
52
  }
53
+ if (formatResultToBehavior !== undefined) {
54
+ this.formatResultToBehavior = formatResultToBehavior;
55
+ }
52
56
  this.userFormatResult = defaultUserFormatResult;
53
57
  Object.assign(this.defaultLogData, defaultData);
54
58
  Object.assign(this.opts, options);
@@ -120,6 +124,7 @@ class DefaultLog {
120
124
  pagePath: () => location.href,
121
125
  pageName: () => document.title,
122
126
  referUrl: () => referUrl.referUrl,
127
+ devision: navigator.userAgent,
123
128
  deviceInfo,
124
129
  terminal: isPC ? 'PC' : mobileInfo.split(' ')[0],
125
130
  ...data,
@@ -144,6 +149,23 @@ class DefaultLog {
144
149
  else {
145
150
  debug && console.log(`logger ${type}`, formatResultObj);
146
151
  }
152
+ if (this.formatResultToBehavior) {
153
+ const masNeedKey = ['appVersion', 'deviceInfo', 'devision', 'entryType', 'moduleName', 'pageName', 'pagePath', 'product', 'referUrl', 'tenantId', 'tenantName', 'terminal', 'type', 'userId', 'userName', 'ext'];
154
+ masNeedKey.forEach((key) => {
155
+ formatResultObj[key] ??= '';
156
+ });
157
+ const ext = {};
158
+ Object.keys(formatResultObj).forEach((key) => {
159
+ if (key === "ext") {
160
+ Object.assign(ext, formatResultObj[key]);
161
+ }
162
+ else if (!masNeedKey.includes(key)) {
163
+ Object.assign(ext, { [key]: formatResultObj[key] });
164
+ delete formatResultObj[key];
165
+ }
166
+ });
167
+ Object.assign(formatResultObj, { ext });
168
+ }
147
169
  tracker.send({
148
170
  ...formatResultObj,
149
171
  });
package/lib/trace.js CHANGED
@@ -34,7 +34,6 @@ export function initTrace(info) {
34
34
  moduleName,
35
35
  entryType: 'click',
36
36
  });
37
- delete target.dataset.click;
38
37
  }
39
38
  };
40
39
  window.addEventListener('click', clickHandler, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zxhy-npm/send-sls-logger",
3
- "version": "1.1.11",
3
+ "version": "1.1.16",
4
4
  "description": "阿里云sls的logger发送",
5
5
  "scripts": {
6
6
  "build": "rm -rf lib && tsc"
package/readme.md CHANGED
@@ -54,3 +54,5 @@ miniLog.info({ msg: "这是一条默认日志" });
54
54
  更新内容: trace 导出deviceInfo 以及 referUrl
55
55
  1.1.5 ---------- 1/10/2025, 11:40:55 AM
56
56
  更新内容: sls 打日志的时候,将deviceInfo、referUrl、pagePath, pageName直接带进去,不需要使用者增加
57
+ 1.1.14 ---------- 3/21/2025, 5:50:32 PM
58
+ 更新内容: 增加了 formatResultToBehavior 字段