UNPKG

miniprogram-logger

Version:

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

46 lines (45 loc) 1.32 kB
import { Reporter, logTransformFunction } from "../common/reporter"; const fileds = ['level', 'action', 'content']; /** * 微信上报API */ export class ReportAnalytics extends Reporter { /** * @example * ``` * new ReportAnalytics<LogObject,[LogLevel,string,any]>('logger',['level', 'action', 'content']) * ``` * @param tableName - 上报的表名 * @param fields - 字段列表,参数表对应,前三个分别是id,record_time,level对应的字段名称 * @param context - 上下文 */ constructor(tableName, fields = fileds, context = {}) { super(tableName, fields, context); /** * 记录日志级别 */ this.logLevels = ['warn', 'error']; this.TransformFunction = logTransformFunction; } debug() { this.logByLevel('debug', arguments); } info() { this.logByLevel('info', arguments); } warn() { this.logByLevel('warn', arguments); } error() { this.logByLevel('error', arguments); } log() { this.report.apply(this, arguments); } logByLevel(level, args) { if (this.logLevels.indexOf(level) !== -1) { Array.prototype.unshift.call(args, level); return this.report.apply(this, args); } } }