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