miniprogram-logger
Version:
It is used to log and gather statistics of users' behavior.
41 lines (40 loc) • 1.04 kB
JavaScript
import { AllLevels, isLogLevel } from "./ILogger";
/**
* 实时日志
*/
export class RelatimeLogger {
/**
* 创建LogManager
* @param wxLogManager - 微信LogManager或者参数
*/
constructor(wxLogManager) {
/**
* 记录日志级别
*/
this.logLevels = AllLevels;
this.manager = wxLogManager || wx.getRealtimeLogManager();
}
debug(...args) {
return this.log('debug', ...args);
}
info(...args) {
return this.log('info', ...args);
}
warn(...args) {
return this.log('warn', ...args);
}
error(...args) {
return this.log('error', ...args);
}
log() {
if (arguments.length > 1 && isLogLevel(arguments[0])) {
const level = arguments[0];
if (this.logLevels.indexOf(level) >= 0) {
this.manager[level].apply(this.manager, Array.prototype.slice.call(arguments, 1));
}
}
else {
this.manager.debug(arguments);
}
}
}