调用云函数打印高级日志的时候一直报log is not defined 的错误?
发布于 5 年前 作者 wei46 9788 次浏览 来自 问答

云函数高级日志

// 云函数入口文件

const cloud = require('wx-server-sdk')

cloud.init({

  env: cloud.DYNAMIC_CURRENT_ENV,

})

// 云函数入口函数

exports.main = async (event, context) => {

  const wxContext = cloud.getWXContext()


  const logabc = cloud.logger()

  logabc.info({

    name: 'xx',

    cost: 10,

    attributes: {

      width: 100,

      height: 200,

    },

    colors: ['red', 'blue'],

  })


  // 输出到日志记录中会有这么一条记录:

  // {

  //   "level": "info",

  //   "name": "xx",

  //   "cost": "10",

  //   "attributes": "{ width: 100, height: 200 }",

  //   "colors": "[ "red", "blue" ]"

  //   ..., // 其他系统字段

  // }


  return {

    event,

    openid: wxContext.OPENID,

    appid: wxContext.APPID,

    unionid: wxContext.UNIONID,

  }

}

回到顶部