@be-link/cls-logger 1.0.1-beta.2 → 1.0.1-beta.21

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.
Files changed (53) hide show
  1. package/README.md +356 -32
  2. package/dist/ClsLogger.d.ts +15 -96
  3. package/dist/ClsLogger.d.ts.map +1 -1
  4. package/dist/ClsLoggerCore.d.ts +177 -0
  5. package/dist/ClsLoggerCore.d.ts.map +1 -0
  6. package/dist/behaviorMonitor.d.ts.map +1 -1
  7. package/dist/clsSdkTypes.d.ts +18 -0
  8. package/dist/clsSdkTypes.d.ts.map +1 -0
  9. package/dist/deviceInfo.d.ts.map +1 -1
  10. package/dist/errorMonitor.d.ts.map +1 -1
  11. package/dist/index.esm.js +2246 -1396
  12. package/dist/index.js +2246 -1396
  13. package/dist/index.umd.js +2249 -1399
  14. package/dist/mini/ClsLogger.d.ts +14 -0
  15. package/dist/mini/ClsLogger.d.ts.map +1 -0
  16. package/dist/mini/behaviorMonitor.d.ts +5 -0
  17. package/dist/mini/behaviorMonitor.d.ts.map +1 -0
  18. package/dist/mini/deviceInfo.d.ts +3 -0
  19. package/dist/mini/deviceInfo.d.ts.map +1 -0
  20. package/dist/mini/errorMonitor.d.ts +5 -0
  21. package/dist/mini/errorMonitor.d.ts.map +1 -0
  22. package/dist/mini/performanceMonitor.d.ts +5 -0
  23. package/dist/mini/performanceMonitor.d.ts.map +1 -0
  24. package/dist/mini/requestMonitor.d.ts +9 -0
  25. package/dist/mini/requestMonitor.d.ts.map +1 -0
  26. package/dist/mini.d.ts +6 -0
  27. package/dist/mini.d.ts.map +1 -0
  28. package/dist/mini.esm.js +1945 -0
  29. package/dist/mini.js +1970 -0
  30. package/dist/performanceMonitor.d.ts.map +1 -1
  31. package/dist/requestMonitor.d.ts +1 -5
  32. package/dist/requestMonitor.d.ts.map +1 -1
  33. package/dist/sdkUtils.d.ts +3 -0
  34. package/dist/sdkUtils.d.ts.map +1 -0
  35. package/dist/types.d.ts +99 -14
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/web/ClsLogger.d.ts +14 -0
  38. package/dist/web/ClsLogger.d.ts.map +1 -0
  39. package/dist/web/behaviorMonitor.d.ts +5 -0
  40. package/dist/web/behaviorMonitor.d.ts.map +1 -0
  41. package/dist/web/deviceInfo.d.ts +3 -0
  42. package/dist/web/deviceInfo.d.ts.map +1 -0
  43. package/dist/web/errorMonitor.d.ts +5 -0
  44. package/dist/web/errorMonitor.d.ts.map +1 -0
  45. package/dist/web/performanceMonitor.d.ts +5 -0
  46. package/dist/web/performanceMonitor.d.ts.map +1 -0
  47. package/dist/web/requestMonitor.d.ts +5 -0
  48. package/dist/web/requestMonitor.d.ts.map +1 -0
  49. package/dist/web.d.ts +6 -0
  50. package/dist/web.d.ts.map +1 -0
  51. package/dist/web.esm.js +2094 -0
  52. package/dist/web.js +2119 -0
  53. package/package.json +36 -2
package/README.md CHANGED
@@ -1,6 +1,16 @@
1
1
  # @be-link/cls-logger
2
2
 
3
- 腾讯云 CLS(`tencentcloud-cls-sdk-js-web`)日志上报封装,参考仓库内 `@be-link/utils` 的构建方式(Rollup 打包 + tsc 仅产出 d.ts)。
3
+ 腾讯云 CLS(`tencentcloud-cls-sdk-js-web` / `tencentcloud-cls-sdk-js-mini`)日志上报封装,支持 Web、H5 和小程序环境,提供统一的调用方式。
4
+
5
+ ## 特性
6
+
7
+ - 自动环境适配(Web / H5 / 小程序)
8
+ - 内存队列批量上报,减少网络请求
9
+ - 页面关闭时 `sendBeacon` 保证日志不丢失
10
+ - 支持浏览器空闲时上报(`requestIdleCallback`)
11
+ - 错误即时上报,信息日志批量上报
12
+ - 自动采集:请求监控、性能监控、错误监控、行为埋点
13
+ - 失败重试 + 本地缓存兜底
4
14
 
5
15
  ## 安装
6
16
 
@@ -8,58 +18,372 @@
8
18
  pnpm add @be-link/cls-logger
9
19
  ```
10
20
 
11
- ## 使用
21
+ ### 依赖说明
22
+
23
+ | 入口 | 依赖 | 说明 |
24
+ | -------------------------- | -------------------------------------------- | ----------------------------------- |
25
+ | `@be-link/cls-logger` | `tencentcloud-cls-sdk-js-web` | 统一入口,自动适配环境 |
26
+ | `@be-link/cls-logger/web` | `tencentcloud-cls-sdk-js-web` + `web-vitals` | Web/H5 专用,含 Web Vitals 性能监控 |
27
+ | `@be-link/cls-logger/mini` | `tencentcloud-cls-sdk-js-mini` | 小程序专用 |
28
+
29
+ > **注意**:所有依赖已内置,无需手动安装。
30
+
31
+ ## 快速开始
32
+
33
+ ### 1. 统一引入方式(推荐快速接入)
12
34
 
13
35
  ```ts
14
- import clsLogger, { ClsLogger } from '@be-link/cls-logger';
36
+ import clsLogger from '@be-link/cls-logger';
15
37
 
16
38
  clsLogger.init({
17
- topic_id: 'xxx',
18
- projectName: 'my-project',
19
- generateBaseFields: () => ({ env: 'prod', uid: 'u_1' }),
39
+ projectId: 'my-project',
40
+ appId: 'my-app-id',
41
+ source: 'my-source',
20
42
  });
43
+ ```
21
44
 
22
- // 直接上报(展开字段)
23
- clsLogger.put({ event: 'login', ok: true });
45
+ ### 2. 分环境引入方式(推荐生产环境)
24
46
 
25
- // 直接上报(JSON 放进单个 key,默认 “日志内容”)
26
- clsLogger.putJson({ event: 'click', x: 1, y: 2 });
47
+ #### Web / H5:
27
48
 
28
- // 入队(写入 localStorage,默认 15 条自动 flush)
29
- clsLogger.enqueue({ event: 'page_view', page: '/home' });
49
+ ```ts
50
+ import { clsLogger } from '@be-link/cls-logger/web';
51
+
52
+ clsLogger.init({
53
+ projectId: 'my-web-project',
54
+ source: 'web-source',
55
+ });
30
56
  ```
31
57
 
32
- ## 请求监控(requestMonitor)
58
+ #### 小程序:
33
59
 
34
- 初始化后默认会开启 HTTP 请求监控(Web/H5:`fetch`/`XMLHttpRequest`;小程序:`wx.request`/`cloud.callFunction`),并把请求信息通过 `track('http', payload)` 上报。
60
+ ```ts
61
+ import { clsLogger } from '@be-link/cls-logger/mini';
35
62
 
36
- - **关闭**:`clsLogger.init({ requestMonitor: false })`
37
- - **忽略上报请求避免递归**:默认会忽略 CLS 上报域名(会把 `endpoint` 自动加入 `ignoreUrls`),并在内部增加了“上报发送”保护,避免上报请求在跨域失败时出现递归上报/死循环。
38
- - **自定义忽略**:`clsLogger.init({ requestMonitor: { ignoreUrls: ['example.com', /\\/internal\\//] } })`
63
+ clsLogger.init({
64
+ projectId: 'my-mini-project',
65
+ appId: 'wx123456789',
66
+ source: 'mini-source',
67
+ });
68
+ ```
39
69
 
40
- ## 性能监控(performanceMonitor)
70
+ ## API
41
71
 
42
- 初始化后默认会开启性能监控,并通过 `track('perf', payload)` 上报,包含:
72
+ ### 日志方法
43
73
 
44
- - **Web Vitals**:FCP/LCP/CLS/FID
45
- - **Navigation Timing**:TTFB 等
46
- - **Resource Timing**:资源加载耗时(`PerformanceObserver({ type: 'resource', buffered: true })`,首屏会比较多)
74
+ ```ts
75
+ // 信息日志(走批量队列)
76
+ clsLogger.info('应用启动', { startUpTime: 120 });
77
+
78
+ // 警告日志(走批量队列)
79
+ clsLogger.warn('资源加载慢', { duration: 3000 });
80
+
81
+ // 错误日志(默认即时上报)
82
+ clsLogger.error('支付失败', { orderId: '123' });
83
+
84
+ // Error 对象(自动解析堆栈)
85
+ try {
86
+ doSomething();
87
+ } catch (err) {
88
+ clsLogger.error(err, { module: 'payment' });
89
+ }
90
+ ```
47
91
 
48
- 常见降噪配置:
92
+ ### 即时上报选项
49
93
 
50
94
  ```ts
51
- import clsLogger from '@be-link/cls-logger';
95
+ // info/warn 强制即时上报
96
+ clsLogger.info('重要事件', { data: 1 }, { immediate: true });
97
+
98
+ // error 走批量队列(默认是即时上报)
99
+ clsLogger.error('非关键错误', { data: 1 }, { immediate: false });
100
+ ```
52
101
 
102
+ ### 自定义埋点
103
+
104
+ ```ts
105
+ clsLogger.track('click_event', {
106
+ button: 'submit',
107
+ page: '/home',
108
+ });
109
+ ```
110
+
111
+ ### 统计埋点
112
+
113
+ ```ts
114
+ clsLogger.stat({
115
+ pageName: '首页',
116
+ scene: '入口',
117
+ subScene: '活动弹窗',
118
+ data: 1,
119
+ });
120
+ ```
121
+
122
+ ## 配置项
123
+
124
+ ### 完整配置示例
125
+
126
+ ```ts
53
127
  clsLogger.init({
54
- topic_id: 'xxx',
55
- projectName: 'my-project',
128
+ // 基础配置
129
+ enabled: true, // 是否启用,默认 true
130
+ projectId: 'my-project', // 项目标识
131
+ appId: 'wx123456789', // 应用 ID(小程序必填)
132
+ appVersion: '1.0.0', // 应用版本
133
+ source: 'my-source', // CLS source
134
+
135
+ // 腾讯云 CLS 配置
136
+ tencentCloud: {
137
+ endpoint: 'https://ap-shanghai.cls.tencentcs.com',
138
+ topicID: 'your-topic-id',
139
+ retry_times: 3,
140
+ },
141
+
142
+ // 批量上报配置
143
+ batch: {
144
+ maxSize: 50, // 队列达到此数量立即发送,默认 20
145
+ intervalMs: 1000, // 定时批量发送间隔,默认 500ms
146
+ startupDelayMs: 3000, // 启动合并窗口,默认 0(不启用)
147
+ useIdleCallback: true, // 使用浏览器空闲时间上报,默认 false
148
+ idleTimeout: 3000, // 空闲回调超时时间,默认 3000ms
149
+ },
150
+
151
+ // 请求监控配置
152
+ requestMonitor: {
153
+ enabled: true, // 是否开启,默认 true
154
+ sampleRate: 1, // 采样率 0~1,默认 1
155
+ ignoreUrls: [/localhost/], // 忽略的 URL
156
+ includeMethod: true, // 是否携带 method,默认 true
157
+ includeQuery: true, // 是否携带 query,默认 true
158
+ includeBody: true, // 是否携带 body,默认 true
159
+ maxParamLength: 2000, // 参数最大长度,默认 2000
160
+ },
161
+
162
+ // 错误监控配置
163
+ errorMonitor: {
164
+ enabled: true, // 是否开启,默认 true
165
+ sampleRate: 1, // 采样率 0~1,默认 1
166
+ captureResourceError: true, // 是否采集资源加载错误,默认 true
167
+ maxTextLength: 4000, // stack/message 最大长度,默认 4000
168
+ dedupeWindowMs: 3000, // 错误去重窗口,默认 3000ms
169
+ dedupeMaxKeys: 200, // 去重缓存最大 key 数,默认 200
170
+ ignoreMessages: [
171
+ // 忽略的错误信息(默认值)
172
+ 'Script error.',
173
+ 'Script error',
174
+ /^ResizeObserver loop/,
175
+ 'Permission was denied',
176
+ ],
177
+ },
178
+
179
+ // 性能监控配置
56
180
  performanceMonitor: {
57
- // 降低采样(0~1)
58
- sampleRate: 0.1,
59
- // 忽略本地开发资源 & sourcemap(按你的资源特征调整)
60
- ignoreUrls: ['localhost:8080', /\\.map$/],
181
+ enabled: true, // 是否开启,默认 true
182
+ sampleRate: 1, // 采样率 0~1,默认 1
183
+ webVitals: true, // 是否采集 Web Vitals(含 TTFB),默认 true
184
+ resourceTiming: true, // 是否采集资源加载耗时,默认 true
185
+ ignoreUrls: [/localhost/], // 忽略的资源 URL
186
+ maxTextLength: 2000, // 性能指标文本最大长度,默认 2000
61
187
  },
62
- // 可选:启动阶段合并窗口,减少首屏 perf/resource 被 intervalMs 拆成多次上报
63
- // batch: { startupDelayMs: 2000 },
188
+
189
+ // 行为埋点配置
190
+ behaviorMonitor: {
191
+ enabled: true, // 是否开启,默认 true
192
+ pv: true, // PV 是否开启,默认 true
193
+ uv: true, // UV 是否开启,默认 true
194
+ click: true, // 点击是否开启,默认 true
195
+ sampleRate: 1, // 采样率 0~1,默认 1
196
+ uvExpireDays: 30, // UV 标识过期天数,默认 30
197
+ clickTrackIdAttr: 'data-track-id', // 点击元素埋点标识属性名
198
+ clickMaxTextLength: 120, // 点击文本最大长度,默认 120
199
+ },
200
+
201
+ // 设备信息配置
202
+ deviceInfo: {
203
+ enabled: true, // 是否开启,默认 true
204
+ includeUserAgent: true, // 是否包含 UA,默认 true
205
+ includeNetwork: true, // 是否包含网络信息,默认 true
206
+ },
207
+
208
+ // 自定义基础字段
209
+ generateBaseFields: () => ({
210
+ userId: getUserId(),
211
+ userName: getUserName(),
212
+ environment: 'production',
213
+ }),
64
214
  });
65
215
  ```
216
+
217
+ ## 常见场景配置
218
+
219
+ ### 场景 1:首屏请求过多
220
+
221
+ 页面首次加载时日志请求过多,影响其他请求:
222
+
223
+ ```ts
224
+ clsLogger.init({
225
+ batch: {
226
+ startupDelayMs: 3000, // 启动 3 秒内的日志合并发送
227
+ maxSize: 100, // 提高队列阈值
228
+ intervalMs: 1000, // 延长批量间隔
229
+ useIdleCallback: true, // 使用浏览器空闲时间上报
230
+ },
231
+ });
232
+ ```
233
+
234
+ ### 场景 2:减少资源监控日志
235
+
236
+ 开发环境资源过多,或生产环境不需要全量资源监控:
237
+
238
+ ```ts
239
+ clsLogger.init({
240
+ performanceMonitor: {
241
+ resourceTiming: false, // 关闭资源监控
242
+ // 或者采样
243
+ // sampleRate: 0.1, // 10% 采样
244
+ // 或者过滤
245
+ // ignoreUrls: [/localhost/, /node_modules/],
246
+ },
247
+ });
248
+ ```
249
+
250
+ ### 场景 3:过滤无意义的错误
251
+
252
+ 过滤第三方 SDK 的跨域错误:
253
+
254
+ ```ts
255
+ clsLogger.init({
256
+ errorMonitor: {
257
+ ignoreMessages: [
258
+ // 默认规则
259
+ 'Script error.',
260
+ 'Script error',
261
+ /^ResizeObserver loop/,
262
+ 'Permission was denied',
263
+ // 自定义规则
264
+ /火山SDK/,
265
+ /VolcEngine/,
266
+ /network error/i,
267
+ ],
268
+ },
269
+ });
270
+ ```
271
+
272
+ ### 场景 4:高并发场景(直播间)
273
+
274
+ ```ts
275
+ clsLogger.init({
276
+ batch: {
277
+ maxSize: 100, // 提高队列阈值
278
+ intervalMs: 2000, // 延长批量间隔
279
+ useIdleCallback: true, // 空闲时上报
280
+ },
281
+ performanceMonitor: {
282
+ resourceTiming: false, // 关闭资源监控
283
+ },
284
+ requestMonitor: {
285
+ sampleRate: 0.1, // 请求监控采样 10%
286
+ },
287
+ });
288
+ ```
289
+
290
+ ## 功能说明
291
+
292
+ ### 1. 批量上报机制
293
+
294
+ SDK 使用内存队列批量上报日志:
295
+
296
+ | 触发条件 | 说明 |
297
+ | -------- | ------------------------------------------------------ |
298
+ | 队列满 | 达到 `maxSize` 立即发送 |
299
+ | 定时器 | 每 `intervalMs` 毫秒发送一次 |
300
+ | 页面关闭 | `visibilitychange` + `pagehide` 触发 `sendBeacon` 发送 |
301
+ | 启动合并 | `startupDelayMs` 窗口内的日志尽量合并 |
302
+
303
+ ### 2. 即时上报 vs 批量上报
304
+
305
+ | 方法 | 默认行为 | 说明 |
306
+ | --------- | -------- | -------------------------------------------------------- |
307
+ | `error()` | 即时上报 | 错误需要及时发现,可通过 `{ immediate: false }` 改为批量 |
308
+ | `info()` | 批量上报 | 可通过 `{ immediate: true }` 改为即时 |
309
+ | `warn()` | 批量上报 | 可通过 `{ immediate: true }` 改为即时 |
310
+ | `track()` | 批量上报 | - |
311
+
312
+ ### 3. 页面关闭保障
313
+
314
+ 页面关闭时(`visibilitychange` / `pagehide`),SDK 会:
315
+
316
+ 1. 使用 `navigator.sendBeacon` 同步发送队列中的日志
317
+ 2. 如果 `sendBeacon` 不可用,将日志缓存到本地存储
318
+ 3. 下次启动时自动重试发送缓存的日志
319
+
320
+ ### 4. 失败重试机制
321
+
322
+ - 上报失败后使用指数退避算法重试
323
+ - 多次重试仍失败,日志落盘到本地缓存
324
+ - 下次应用启动时自动尝试重新上报
325
+ - 本地缓存最多保留 200 条(可配置 `failedCacheMax`)
326
+
327
+ ### 5. 自动采集内容
328
+
329
+ #### 请求监控
330
+
331
+ - **Web**: 拦截 `fetch` / `XMLHttpRequest`
332
+ - **小程序**: 拦截 `wx.request` / `wx.cloud.callFunction`
333
+
334
+ #### 性能监控
335
+
336
+ - **Web**: 使用 [Google web-vitals](https://github.com/GoogleChrome/web-vitals) 库实现
337
+ - **FCP** (First Contentful Paint): 首次内容渲染
338
+ - **LCP** (Largest Contentful Paint): 最大内容渲染(用户交互后自动停止)
339
+ - **CLS** (Cumulative Layout Shift): 累积布局偏移(5秒会话窗口算法)
340
+ - **INP** (Interaction to Next Paint): 交互到绘制延迟(替代 FID)
341
+ - **TTFB** (Time to First Byte): 首字节时间
342
+ - **资源加载耗时**: PerformanceResourceTiming
343
+ - 自动处理 BFCache 恢复时的指标重置
344
+ - 上报数据包含 `rating` 字段:`'good'` | `'needs-improvement'` | `'poor'`
345
+ - **小程序**: 首屏渲染、路由切换、启动耗时
346
+
347
+ #### 错误监控
348
+
349
+ - **Web**: `window.onerror`, `unhandledrejection`, 资源加载错误
350
+ - **小程序**: `wx.onError`, `wx.onUnhandledRejection`, `App.onError`
351
+
352
+ #### 行为埋点
353
+
354
+ - **PV**: 页面访问
355
+ - **UV**: 用户访问(自动生成持久化 ID)
356
+ - **点击**: 带 `data-track-id` 属性的元素点击
357
+
358
+ ## 手动注入 SDK
359
+
360
+ 在某些特殊构建环境下,可以手动注入 SDK:
361
+
362
+ ```ts
363
+ import { clsLogger } from '@be-link/cls-logger/mini';
364
+ import * as MiniSdk from 'tencentcloud-cls-sdk-js-mini';
365
+
366
+ clsLogger.init({
367
+ tencentCloud: { topicID: 'xxx', endpoint: 'xxx' },
368
+ sdk: MiniSdk,
369
+ });
370
+ ```
371
+
372
+ ## 类型定义
373
+
374
+ ```ts
375
+ import type {
376
+ ClsLoggerInitOptions,
377
+ BatchOptions,
378
+ ReportOptions,
379
+ RequestMonitorOptions,
380
+ ErrorMonitorOptions,
381
+ PerformanceMonitorOptions,
382
+ BehaviorMonitorOptions,
383
+ DeviceInfoOptions,
384
+ } from '@be-link/cls-logger';
385
+ ```
386
+
387
+ ## License
388
+
389
+ MIT
@@ -1,98 +1,17 @@
1
- import { AsyncClient } from 'tencentcloud-cls-sdk-js-web';
2
- import type { ClsLoggerInitOptions, FlatFields, PutOptions, QueueItem, ReportLog } from './types';
3
- export declare class ClsLogger {
4
- private client;
5
- private topicId;
6
- private endpoint;
7
- private retryTimes;
8
- private source;
9
- private projectId;
10
- private projectName;
11
- private appId;
12
- private appVersion;
13
- private envType;
14
- private userGenerateBaseFields;
15
- private autoGenerateBaseFields;
16
- private storageKey;
17
- private batchSize;
18
- private memoryQueue;
19
- private batchMaxSize;
20
- private batchIntervalMs;
21
- private batchTimer;
22
- private batchTimerDueAt;
23
- private initTs;
24
- private startupDelayMs;
25
- private failedCacheKey;
26
- private failedCacheMax;
27
- private requestMonitorStarted;
28
- private errorMonitorStarted;
29
- private performanceMonitorStarted;
30
- private behaviorMonitorStarted;
31
- private behaviorMonitorCleanup;
32
- userId: unknown;
33
- userName: unknown;
34
- init(options: ClsLoggerInitOptions): void;
35
- private getBaseFields;
36
- private startRequestMonitor;
37
- private startErrorMonitor;
38
- private startPerformanceMonitor;
39
- private startBehaviorMonitor;
40
- /**
41
- * 停止行为埋点监听(PV/UV/点击)
42
- * - 如需重启:可再次调用 init(或自行调用 init 后的默认启动逻辑)
43
- */
44
- stopBehaviorMonitor(): void;
45
- getInstance(): AsyncClient;
46
- private detectEnvType;
47
- /**
48
- * 直接上报:埋点入参必须是一维(扁平)Object
49
- * - 非原始值(对象/数组等)会被自动 stringify 成 string
50
- * - 最终会把 fields 展开成 CLS 的 content(key/value 都会转成 string)
51
- */
52
- put(fields: FlatFields, options?: PutOptions): void;
53
- /**
54
- * 直接上报:把 data 序列化后放入指定 key(默认 “日志内容”)
55
- */
56
- putJson(data: unknown, clsLoggerKey?: string, options?: PutOptions): void;
57
- /**
58
- * 入队:写入 localStorage 队列;达到 batchSize 自动 flush
59
- * - 埋点入参必须是一维(扁平)Object,非原始值会被 stringify
60
- */
61
- enqueue(fields: FlatFields, options?: PutOptions): void;
62
- /**
63
- * 从 localStorage 读取队列并批量上报
64
- */
65
- flush(): void;
66
- /**
67
- * 批量上报(每条 item.data 展开为 log content)
68
- */
69
- putBatch(queue: QueueItem[]): void;
70
- /**
71
- * 参考《一、概述》:统一上报入口(内存队列 + 批量发送)
72
- */
73
- report(log: ReportLog): void;
74
- private getDesiredBatchFlushDueAt;
75
- info(message: string, data?: FlatFields): void;
76
- warn(message: string, data?: FlatFields): void;
77
- error(message: string, data?: FlatFields): void;
78
- track(trackType: string, data?: FlatFields): void;
79
- /**
80
- * 立即发送内存队列
81
- */
82
- flushBatch(): Promise<void>;
83
- private buildReportFields;
84
- private sendReportLogs;
85
- private retrySendReportLogs;
86
- private cacheFailedReportLogs;
87
- flushFailed(): void;
88
- /**
89
- * 统计/计数类日志:按字段展开上报(若 data 为空默认 1)
90
- */
91
- stat(param: {
92
- pageName: string;
93
- scene: string;
94
- subScene: string;
95
- data?: number | string;
96
- }): void;
1
+ import { ClsLoggerCore } from './ClsLoggerCore';
2
+ import type { ClsSdkModule } from './clsSdkTypes';
3
+ import type { FlatFields, RequestMonitorOptions, ErrorMonitorOptions, PerformanceMonitorOptions, BehaviorMonitorOptions, DeviceInfoOptions } from './types';
4
+ /**
5
+ * 兼容版 ClsLogger(默认入口)
6
+ * - 保留了自动识别环境 + 动态 import 的逻辑
7
+ * - 如果业务想瘦身,建议改用 @be-link/cls-logger/web 或 /mini
8
+ */
9
+ export declare class ClsLogger extends ClsLoggerCore {
10
+ protected loadSdk(): Promise<ClsSdkModule>;
11
+ protected installRequestMonitor(report: (type: string, data: FlatFields) => void, options: RequestMonitorOptions): void;
12
+ protected installErrorMonitor(report: (type: string, data: FlatFields) => void, options: boolean | ErrorMonitorOptions): void;
13
+ protected installPerformanceMonitor(report: (type: string, data: FlatFields) => void, options: boolean | PerformanceMonitorOptions): void;
14
+ protected installBehaviorMonitor(report: (type: string, data: FlatFields) => void, options: boolean | BehaviorMonitorOptions): () => void;
15
+ protected createDeviceInfoBaseFields(options: boolean | DeviceInfoOptions | undefined): (() => FlatFields) | null;
97
16
  }
98
17
  //# sourceMappingURL=ClsLogger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ClsLogger.d.ts","sourceRoot":"","sources":["../src/ClsLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAiC,MAAM,6BAA6B,CAAC;AAEzF,OAAO,KAAK,EACV,oBAAoB,EAGpB,UAAU,EAEV,UAAU,EACV,SAAS,EACT,SAAS,EAEV,MAAM,SAAS,CAAC;AA2BjB,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,OAAO,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