UNPKG

miniprogram-logger

Version:

It is used to log and gather statistics of users' behavior.

49 lines (48 loc) 1.79 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var reporter_1 = require("../common/reporter"); var guid_1 = require("../common/guid"); /** * 默认 Telemetry对象转换函数 * 字段中注入`id`和`extension.timestamp` * @param data LogObject */ function TelemetryTransformFunction(data) { if (typeof data === "object") { if (!data.id) { data.id = guid_1.guid(); } if (!data.extension) { data.extension = {}; } data.extension.timestamp = new Date().toISOString(); } return data; } exports.TelemetryTransformFunction = TelemetryTransformFunction; var ReportAnalytics = /** @class */ (function (_super) { __extends(ReportAnalytics, _super); function ReportAnalytics(tableName, context) { var _this = _super.call(this, tableName, ['action', 'param', 'extension', 'user'], context) || this; _this.TransformFunction = TelemetryTransformFunction; return _this; } ReportAnalytics.prototype.record = function () { this.report.apply(this, arguments); }; return ReportAnalytics; }(reporter_1.Reporter)); exports.ReportAnalytics = ReportAnalytics;