// ////////////////////////////////////////////////////////////////////////////// // // Copyright (C) 2016-present All Rights Reserved. // Licensed under the Apache License, Version 2.0 (the "License"); // http://www.apache.org/licenses/LICENSE-2.0 // // Github Home: https://github.com/AlexWang1987 // Author: AlexWang // Date: 2016-08-27 22:58:47 // QQ Email: 1669499355@qq.com // Last Modified time: 2016-08-27 23:05:53 // Description: LiveClass-Loger // // ////////////////////////////////////////////////////////////////////////////// class Loger { constructor(info) { this.sdkInfo = info || ''; this.id = this.initId(); } initId() { if(!this.sdkInfo){ console.log("this.sdkInfo无效-->",this.sdkInfo); return ''; } const infoType = Object.prototype.toString.call(this.sdkInfo); if (infoType === '[object String]') { return this.sdkInfo; } if (infoType === '[object Object]') { return this.sdkInfo.mid || ''; } return ''; /* const infoType = this.sdkInfo.constructor.name.toLowerCase(); if (infoType === 'string') { return this.sdkInfo; } if (infoType === 'object') { return this.sdkInfo.mid || ''; } return '';*/ } log(...msg) { this._log(Loger.LOG, msg); } warn(...msg) { this._log(Loger.WARN, msg); } error(...msg) { this._log(Loger.ERROR, msg); } data(...msg) { this._log(Loger.DATA, msg); } _log(type, msg) { if(!Loger.IS_DEBUG){ return; } msg = JSON.stringify(msg); let logMsg = `${this.id} -> ${msg}`; if (type >= Loger.logLevel) { switch (type) { case Loger.LOG: console.log(logMsg); break; case Loger.WARN: console.warn(logMsg); break; case Loger.ERROR: console.error(logMsg); break; case Loger.DATA: console.log(logMsg); break; } } } } Loger.IS_DEBUG=true; Loger.LOG = 0; Loger.WARN = 1; Loger.ERROR = 2; Loger.NO = Infinity; Loger.logLevel = Loger.LOG; Loger.DATA = 5; export default { getLoger: function getLoger(info) { return new Loger(info); }, setLogLevel: function setLogLevel(logLevel) { Loger.logLevel = logLevel; }, setLogDebug: function setLogDebug(isDebug) { Loger.IS_DEBUG = isDebug; }, LOG: Loger.LOG, WARN: Loger.WARN, ERROR: Loger.ERROR, NO: Loger.NO, DATA: Loger.DATA, IS_DEBUG:Loger.IS_DEBUG, };