3.2.3 • Published 6 years ago
miniprogram-logger v3.2.3
miniprogram-logger
It is used to logger and gather statistics of users' behavior by using wx.reportAnalytics
example
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");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 isLogLevelor not
Class
ConsoleManagerCounterReportMonitorLogReporterLogManagerLogObjectLogLevelTelemetryReporterTimeReporterPerformanceObject
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
日志对象
{
"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 时间戳 |
TelemetryObject
记录 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 | 客户端脱敏数据 |
TimeReporter
时间统计对象
{
"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 时间戳 |
App Error
import { inject } from "miniprogram-logger";
inject(); //自动记录全局错误task flow
+------------+
+-----------------------+--->+ monitor | 监控报警
| count | +------------+
| |
+--------+----------+ | +------------+
| | Filter +----> |
| +-----------------> Console | 命令行
log/info/... | | | |
+------------> | | +------------+
| | +------------+
telemetry | | Filter | |
+------------> | +---------------->+ LogManager | 本地文件
| | | |
time/timeLog | logger | +------------+
+------------> | | +------------+
| | Filter | |
| +---------------->+ Reporter | 微信后端
| | | |
| | +------------+
| | Filter | |
| +---------------->+ realTimeLog| 实时日志
| | | |
+-------------------+ +------------+3.2.3
6 years ago
3.2.2
6 years ago
3.2.1
6 years ago
3.2.0
6 years ago
3.0.2
6 years ago
3.0.1
6 years ago
3.0.0
6 years ago
2.0.0
7 years ago
1.3.3
7 years ago
1.3.2
7 years ago
1.3.1
7 years ago
1.2.1
7 years ago
1.2.0
7 years ago
1.1.0
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago
0.0.8
7 years ago
0.0.7
7 years ago
0.0.6
7 years ago
0.0.5
7 years ago
0.0.4
7 years ago
0.0.3
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago


