我正在使用 Winston for Node 将日志行输出到 Loggly。我遇到了一个问题,我无法解决将日志行输出到控制台的位置,但它们从未出现在 Loggly 中。有趣的是,一些日志行出现在 Loggly 中,而另一些则没有。
这是控制台数据:
info: Lambda: createCustomer(dev): Function called to create customer in DynamoDB. Attempt #1
info: Lambda: createCustomer(dev): Successfully created customer (6196434835540541440) on attempt #1 Attempting to create a ZOHO customer record
error: Lambda: createCustomer(dev): Error creating ZOHO customer (Enter a valid Customer Name). Attempting to delete customer (6196434835540541440) from FS database
info: Lambda: createCustomer(dev): FS customer (6196434835540541440) was successfully backed out.
以下是 Loggly 中出现的内容:
2016-10-24 17:39:49.462 {"level":"info","message":"Lambda: createCustomer(dev): Function called to create customer in DynamoDB. Attempt #1"}
2016-10-24 17:39:49.792 {"level":"info","message":"Lambda: createCustomer(dev): Successfully created customer (6196434835540541440) on attempt #1 Attempting to create a ZOHO customer record"}
我不明白为什么对 watson.log 的调用会输出到控制台,但永远不会到达 Loggly。我的脚本是否有可能在 watson.log 完成之前“结束”所以它只是中止(这是一个 lambda 函数)?
简化代码:
exports.handler = (event, context, callback) => {
createCustomer(event, callback);
}
function createCustomer(event, callback) {
docClient.put(event.body, function(err, data) {
if (err) {
// code to try to create the customer 3 times then fail.
}
else {
winston.log('info', 'This log line will output to both the console and Loggly.');
updateCustId(event, data.customer_id, function(err, data) {
if (err)
winston.log('error','This will output to console but not appear in Loggly.');
else
winston.log('error','This will output to console but not appear in Loggly.');
callback(null, event.body.Item);
});
}
});
}