miniprogram-logger
Version:
It is used to log and gather statistics of users' behavior.
67 lines (66 loc) • 2.5 kB
JavaScript
;
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 fileds = ['level', 'action', 'content'];
/**
* 微信上报API
*/
var ReportAnalytics = /** @class */ (function (_super) {
__extends(ReportAnalytics, _super);
/**
* @example
* ```
* new ReportAnalytics<LogObject,[LogLevel,string,any]>('logger',['level', 'action', 'content'])
* ```
* @param tableName - 上报的表名
* @param fields - 字段列表,参数表对应,前三个分别是id,record_time,level对应的字段名称
* @param context - 上下文
*/
function ReportAnalytics(tableName, fields, context) {
if (fields === void 0) { fields = fileds; }
if (context === void 0) { context = {}; }
var _this = _super.call(this, tableName, fields, context) || this;
/**
* 记录日志级别
*/
_this.logLevels = ['warn', 'error'];
_this.TransformFunction = reporter_1.logTransformFunction;
return _this;
}
ReportAnalytics.prototype.debug = function () {
this.logByLevel('debug', arguments);
};
ReportAnalytics.prototype.info = function () {
this.logByLevel('info', arguments);
};
ReportAnalytics.prototype.warn = function () {
this.logByLevel('warn', arguments);
};
ReportAnalytics.prototype.error = function () {
this.logByLevel('error', arguments);
};
ReportAnalytics.prototype.log = function () {
this.report.apply(this, arguments);
};
ReportAnalytics.prototype.logByLevel = function (level, args) {
if (this.logLevels.indexOf(level) !== -1) {
Array.prototype.unshift.call(args, level);
return this.report.apply(this, args);
}
};
return ReportAnalytics;
}(reporter_1.Reporter));
exports.ReportAnalytics = ReportAnalytics;