@zxhy-npm/send-sls-logger 1.0.2 → 1.0.3

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
@@ -11,16 +11,11 @@ interface LogOptions {
11
11
  count?: number;
12
12
  }
13
13
  export interface InitConfig<T extends LogOptions> {
14
- /** 是否开启debug模式 */
15
14
  debug?: boolean;
16
- /** 日志默认值,可以配置字符串或者function,如果是function,每次发送日志都会执行,通常用于获取当前页面的url等 */
17
15
  defaultData?: StringObject;
18
- /** 设置关键字列表,用于排除一些日志,如果日志中包含配置的这些关键字,则不发送日志 */
19
16
  defaultExclude?: string[];
20
17
  options?: T;
21
- /** 最大字符长度,如果关键字里包含token,则不进行截断 */
22
18
  strMaxLength?: number;
23
- /** 对最终发送的日志进行兜底处理,只能在init中使用 */
24
19
  userFormatResult?: FormatResult;
25
20
  }
26
21
  declare class DefaultLog<T extends LogOptions> {
@@ -39,7 +34,7 @@ declare class DefaultLog<T extends LogOptions> {
39
34
  private maxLength;
40
35
  private Tracker;
41
36
  constructor(Tracker: new (config: T) => any, config: InitConfig<T>);
42
- /** init 可以多次调用,最好在初次,填入 options 内容 */
37
+ /** 初始化日志配置,可以多次调用 */
43
38
  init(config: InitConfig<T>): void;
44
39
  private formatDataMaxLength;
45
40
  private formatFunctionObj;
package/lib/init.js CHANGED
@@ -10,7 +10,7 @@ class DefaultLog {
10
10
  project: '',
11
11
  logstore: '',
12
12
  time: 5,
13
- count: 10, // 发送日志的数量大小,默认是10条。
13
+ count: 10,
14
14
  };
15
15
  defaultLogData = {};
16
16
  exclude = [];
@@ -23,12 +23,10 @@ class DefaultLog {
23
23
  this.Tracker = Tracker;
24
24
  this.init(config);
25
25
  }
26
- /** init 可以多次调用,最好在初次,填入 options 内容 */
26
+ /** 初始化日志配置,可以多次调用 */
27
27
  init(config) {
28
28
  const { defaultData = {}, defaultExclude = [], options, strMaxLength = defaultMaxLength, debug: defaultDebug = false, userFormatResult: defaultUserFormatResult = (_) => _, } = config;
29
- if (defaultDebug !== undefined) {
30
- this.debug = defaultDebug;
31
- }
29
+ this.debug = defaultDebug;
32
30
  this.userFormatResult = defaultUserFormatResult;
33
31
  Object.assign(this.defaultLogData, defaultData);
34
32
  Object.assign(this.opts, options);
@@ -109,9 +107,12 @@ class DefaultLog {
109
107
  formatResultObj = activeFormatResult?.(formatResultObj) || formatResultObj;
110
108
  }
111
109
  if (isExcludeMsg) {
112
- debug && console.log(`logger ${type}`, formatResultObj);
110
+ debug && console.log(`该日志已被忽略:`, formatResultObj);
113
111
  return;
114
112
  }
113
+ else {
114
+ debug && console.log(`logger ${type}`, formatResultObj);
115
+ }
115
116
  tracker.send(formatResultObj);
116
117
  }
117
118
  send(type) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zxhy-npm/send-sls-logger",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "阿里云sls的logger发送",
5
5
  "scripts": {
6
6
  "build": "rm -rf lib && tsc"
@@ -31,4 +31,4 @@
31
31
  "@aliyun-sls/web-track-browser": "^0.0.3",
32
32
  "@aliyun-sls/web-track-mini": "^0.0.2"
33
33
  }
34
- }
34
+ }