尝试使用不同的解析器时 cb 不是函数
cb is not a function when trying to use a different parser
我在存储桶中有 s3 服务器访问日志,我正在尝试使用 lambda 函数将它们传送到 AWS 上的 ElasticSearch 服务。
The example lambda function that I'm using, which uses clf-parser
to paste apache common log files. Since I want to use s3-log-parser,我做了以下修改:
// instead of
var parse = require('clf-parser');
// I have
var s3logparser = require('s3-log-parser');
// instead of
var logRecord = parse(line.toString());
// I have
var logRecord = s3LogParser.parse(line.toString());`
然后我得到
ReferenceError: s3LogParser is not defined
我是不是调用错了模块?我做了 var s3LogParser= require('s3-log-parser');
来修复那个错误,现在我得到 TypeError: cb is not a function
我注意到在 s3 解析器的 index.js 中有这一行:cb(null, parsedLogs);
...试图弄清楚如何解决这个回调问题...
看起来好像 s3-log-parser
模块需要一个回调并且 return 它的 parse()
函数没有任何东西,即使该函数是 100% 同步的。因此,获取解析日志的唯一方法是提供回调函数。
var logRecord = s3LogParser.parse(line.toString(), function (err, lines) {
logRecord = lines
})
console.log(logRecord)
编辑
改用 s3-access-log-parser (example):
var s3alp = require("s3-access-log-parser")
var bogusCharacters = new RegExp(String.fromCharCode(8204, 8203), 'g')
var logRecord = s3alp(line.toString().replace(bogusCharacters, ''))
我在存储桶中有 s3 服务器访问日志,我正在尝试使用 lambda 函数将它们传送到 AWS 上的 ElasticSearch 服务。
The example lambda function that I'm using, which uses clf-parser
to paste apache common log files. Since I want to use s3-log-parser,我做了以下修改:
// instead of
var parse = require('clf-parser');
// I have
var s3logparser = require('s3-log-parser');
// instead of
var logRecord = parse(line.toString());
// I have
var logRecord = s3LogParser.parse(line.toString());`
然后我得到
ReferenceError: s3LogParser is not defined
我是不是调用错了模块?我做了 var s3LogParser= require('s3-log-parser');
来修复那个错误,现在我得到 TypeError: cb is not a function
我注意到在 s3 解析器的 index.js 中有这一行:cb(null, parsedLogs);
...试图弄清楚如何解决这个回调问题...
看起来好像 s3-log-parser
模块需要一个回调并且 return 它的 parse()
函数没有任何东西,即使该函数是 100% 同步的。因此,获取解析日志的唯一方法是提供回调函数。
var logRecord = s3LogParser.parse(line.toString(), function (err, lines) {
logRecord = lines
})
console.log(logRecord)
编辑
改用 s3-access-log-parser (example):
var s3alp = require("s3-access-log-parser")
var bogusCharacters = new RegExp(String.fromCharCode(8204, 8203), 'g')
var logRecord = s3alp(line.toString().replace(bogusCharacters, ''))