资源加载中... loading...

Logger

Author: fmzero, Date: 2019-06-11 09:47:13
Tags: Tool

设置不同的level,控制日志输出等级


//var COLOR_ERROR = "#FF0000"
//var COLOR_WARN = "#FF0000"
//var COLOR_INFO = "#0000FF"
//var COLOR_DEBUG = "#000000"
var LEVER_PATTERN = {
  DEBUG: 0,
  INFO: 1,
  WARNING: 2,
  ERROR: 3
}
//var loggerLever = [LEVER_PATTERN.DEBUG, LEVER_PATTERN.INFO, LEVER_PATTERN.WARNING, LEVER_PATTERN.ERROR][level]
$.Error = function(msg) {
  Log('[ERR] ', msg, '#FF0000')
}

$.Warn = function(msg) {
  if(level <= LEVER_PATTERN.WARNING) {
    Log('[WAR] ', msg, '#FF0000')
  }  
}

$.Info = function(msg) {
  if(level <= LEVER_PATTERN.INFO) {
    Log('[INF] ', msg, '#0000FF')
  }
}

$.Debug = function(msg) {
  if(level <= LEVER_PATTERN.DEBUG) {
    Log('[DBG] ', msg, '#000000')
  }
}

function main() {
  $.Error('this is error')
  $.Warn('this is warn')
  $.Info('this is info')
  $.Debug('this is debug')
}


Related

More