通过封装自定义日志等级,在不同环境展示不同信息。

import { Toast } from 'mint-ui'
import config from '@/config'

/**
 * 1:ALL
 * 2:DEBUG
 * 3:INFO
 * 4:WARN
 * 5:ERROR  错误日志
 * 6:DEAL  需要处理
 * 7:FATAL 系统严重错误
 * @param params
 * @constructor
 */
export const Log = {
  all: (params) => {
    EulerLog(params, 1)
  },
  debug: (params) => {
    EulerLog(params, 2)
  },
  info: (params) => {
    EulerLog(params, 3)
  },
  warn: (params) => {
    EulerLog(params, 4)
  },
  error: (params) => {
    EulerLog(params, 5)
  },
  deal: (params) => {
    EulerLog(params, 6)
  },
  fatal: (params) => {
    EulerLog(params, 7)
  }
}

const EulerLog = function (params, level) {
  if (level >= config.logLevel[process.env.NODE_ENV]) {
    Toast(params)
  } else {
    console.log(params)
  }
}

 

Logo

前往低代码交流专区

更多推荐