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

控制日志输出等级

Author: 扫地僧, Date: 2021-11-05 10:22:30
Tags: 扩展工具JavaScript

设置不同的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')
}

template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6