类名 common/util/Log.js
import { LogType } from '../base/enum'
import { Zondy } from '../base'

/**
 * 日志打印对象
 * @class Log
 */
class Log {
  constructor() {}

  /**
   * 打印info信息,用法参考console.log
   * */
  static info() {
    // 检查是否要输出info日志
    if (
      [LogType.info, LogType.all, LogType.infoAndError].indexOf(Zondy.LogType) >
      -1
    ) {
      const args = Array.prototype.slice.call(arguments)
      args.unshift(
        '%c info ',
        'color:rgb(255,128,0);background-color: wheat;border: 1px solid rgb(255,128,0);border-radius: 3px;'
      )
      // eslint-disable-next-line prefer-spread
      console.log.apply(console, args)
    }
  }

  /**
   * 打印error信息,用法参考console.log
   * */
  static error() {
    // 检查是否要输出error日志
    if (
      [LogType.error, LogType.all, LogType.infoAndError].indexOf(
        Zondy.LogType
      ) > -1
    ) {
      const args = Array.prototype.slice.call(arguments)
      const errStr = args.toString()
      args.unshift(
        '%c error ',
        'color:rgb(255,0,0);background-color: rgb(250,181,181);border: 1px solid rgb(255,0,0);border-radius: 3px;'
      )
      // eslint-disable-next-line prefer-spread
      console.log.apply(console, args)
      throw new Error(errStr)
    }
  }
}

export default Log
构造函数
成员变量
方法
事件