自定义console.log的样式

522 阅读1分钟

修改chrome浏览器

把这里勾上

项目里

window.devtoolsFormatters = [
  {
    header: function (v) {
      if (v?.__styled) {
        const style = `
          color: red;
          border: dotted 1px gray;
          padding: 3px;
        `
        const content = `${JSON.stringify(v.value, null, 2)}`
        return ['div', { style }, content]
      }
    },
    hasBody: function () {
      return false
    },
  },
]

console.logs = function (...args) {
  const vArr = args
  console.log(
    ...vArr.map((v) => {
      return {
        value: v,
        __styled: true,
      }
    })
  )
}

使用

console.logs('tom', { name: 'tom' })
console.logs('12121211')

cool