分享控制台打印各种颜色的日志
发布于 4 年前 作者 xiuying05 1797 次浏览 来自 分享

只用 console.log .error …… 是不是太单调了。

调试的时候可以这样:

代码:
    Util.logwarn('on ready - test', 'log')
    Util.log(TAG, 'yyy', 123, 2131231231, 'xxxx', 'info')
    Util.logerr(TAG,  '123', 'xxx')
    Util.logtag(TAG+'测试: ', ' value= ', this.data.menulist)

util.js:
    function log(tag, ...info) {
      var s = info
      for (let item of info)
        s += JSON.stringify(item)
      console.info(`%c ${tag}${s}`, 'background-color: #25cbe9;color:white; ')
    }    
    //……
    function logtag(tag, ...info) {
      console.info(`%c ${tag}`, 'background-color: orange;color:green;', ...info)
    }
1 回复
回到顶部