从Lambda(Node.js)更改Cloudwatch日志的日志格式

时间:2017-03-16 20:11:52

标签: node.js amazon-web-services aws-lambda amazon-cloudwatch

如果我在代码中执行 Sub dupes() Dim MyRange As Range Dim RowNum As Long RowNum = 1 With Application .ScreenUpdating = False .EnableEvents = False End With Set MyRange = Range("A2:N14200") 'for test only, on the real sub it's dynamic MyRange.Sort key1:=Range("A2"), order1:=xlAscending For Each Row In MyRange With Cells While Cells(RowNum, 1) = Cells(RowNum + 1, 1) And Cells(RowNum + 1, 1) <> "" 'very important the second condition or it will continue to loop forever For i = 3 To 14 Cells(RowNum, i) = Cells(RowNum, i) + Cells(RowNum + 1, i) Next Rows(RowNum + 1).EntireRow.Delete Wend End With RowNum = RowNum + 1 Next With Application .ScreenUpdating = True .EnableEvents = True End With End Sub ,它会在Cloudwatch中显示为
console.log('message')

有没有办法删除自动格式,以便Cloudwatch只显示我传递给2017-03-16T18:58:21.823Z 863c835c-0a7a-11e7-9140-e5018d6e5029 message的参数?

1 个答案:

答案 0 :(得分:5)

在处理程序中,您可以覆盖console.log直接写入stdout

var util = require('util')

module.exports.handler = function (event, context, done) {
  console.log = function () {
    var args = Array.prototype.slice.call(arguments)
    process.stdout.write(args.map(function (arg) {
      return util.isPrimitive(arg) ? String(arg) : util.inspect(arg)
    }).join(' '))
  }

  // the rest of your handler...
}