如果我在我的代码中使用console.log('message')
,它会在Cloudwatch中显示为
2017-03-16T18:58:21.823Z 863c835c-0a7a-11e7-9140-e5018d6e5029 message
。从Lambda(Node.js)更改Cloudwatch日志的日志格式
是否有任何方法可以删除自动格式设置,以便Cloudwatch只显示我传递给console.log
的参数?
如果我在我的代码中使用console.log('message')
,它会在Cloudwatch中显示为
2017-03-16T18:58:21.823Z 863c835c-0a7a-11e7-9140-e5018d6e5029 message
。从Lambda(Node.js)更改Cloudwatch日志的日志格式
是否有任何方法可以删除自动格式设置,以便Cloudwatch只显示我传递给console.log
的参数?
内部处理程序可以覆盖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...
}
什么“自动格式化你指的是每个LAMBDA日志消息被换成了一个时间戳和拉姆达调用ID没有这些信息?日志会是一团糟 –
这是自动格式化,请求ID很容易被减少到更少的字符,可以在时间,请求ID和消息之间添加分隔符,以便更容易解析...你知道吗如何修复它? – maniciam