miniprogram-logger
It is used to logger and gather statistics of users' behavior by using wx.reportAnalytics
example
;logger.debug"action", "log something", correlation_id;logger.info"action2", "info or content", correlation_id;logger.warn"action2", "important messages", correlation_id;logger.error"action2", , correlation_id; // 开始计时开始logger.time"timer-label", ;// 完成计时结束logger.timeEnd"timer-label"; // 耗时统计一次写入logger.timeLog"action", 1000, , "request-ID", ,"type";logger.timeLog; // 用户行为统计logger.telemetry"do something", , ; // 全局参数设置logger.setContext"key", "value";
API
Const object
logger
统一的默认 logger 对象,类似 console api 方式封装下面全部 (推荐使用)defaultCounter
默认计数上报对象defaultLogManager
本地日志管理对象defaultLogReporter
自定义分析日志上报对象defaultTimer
耗时统计上报对象defaultTelemetry
用户行为统计上报对象
Function
inject()
listen and log the app onError/onPageNotFoundguid()
get a UUID like stringisLogLevel(level:any)
level isLogLevel
or not
Class
ConsoleManager
CounterReportMonitor
LogReporter
LogManager
LogObject
LogLevel
TelemetryReporter
TimeReporter
PerformanceObject
Install
npm i miniprogram-logger -S
1. Create the data event in the MiniProgram backend as follow:(Reference: )
https://developers.weixin.qq.com/miniprogram/analysis/custom/
自定义记录表
id
和record_time
默认会自动生成
下列所有非number
类型均对应string
DefaultLogObject
日志对象
上报事件名log
;
表结构
字段 | 类型 | 说明 |
---|---|---|
id | string | 单条记录过滤 ID |
level | string | 日志级别 |
action | string | 操作 |
content | string | 内容 |
correlation_id | string | 关联 ID |
user | string | 客户端脱敏数据 |
timestamp | string | ISO 时间戳 |
TelemetryObject
记录 Telemetry
自定上报默认事件名telemetry
;
表结构
字段 | 类型 | 说明 |
---|---|---|
id | string | 单条记录过滤 ID |
action | string | 操作 |
param | string | 参数 |
extension | string | 其它数据 |
user | string | 客户端脱敏数据 |
TimeReporter
时间统计对象
自定上报默认事件名time
;
表结构
字段 | 类型 | 说明 |
---|---|---|
id | string | 单条记录过滤 ID |
action | string | 操作 |
time | number | 操作耗时 |
param | string | 参数 |
correlation_id | string | 关联 ID |
result | string | 操作结果 |
type | string | 操作分类 |
user | string | 客户端脱敏数据 |
timestamp | string | ISO 时间戳 |
App Error
;; //自动记录全局错误
task flow
+------------+
+-----------------------+--->+ monitor | 监控报警
| count | +------------+
| |
+--------+----------+ | +------------+
| | Filter +----> |
| +-----------------> Console | 命令行
log/info/... | | | |
+------------> | | +------------+
| | +------------+
telemetry | | Filter | |
+------------> | +---------------->+ LogManager | 本地文件
| | | |
time/timeLog | logger | +------------+
+------------> | | +------------+
| | Filter | |
| +---------------->+ Reporter | 微信后端
| | | |
| | +------------+
| | Filter | |
| +---------------->+ realTimeLog| 实时日志
| | | |
+-------------------+ +------------+