gpt4 book ai didi

node.js - winston-elasticsearch 在记录时创建回调错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:06:51 27 4
gpt4 key购买 nike

使用“winston-elasticsearch”时,我在记录消息时收到此错误:

TypeError: callback is not a function

我的代码:

const winston = require("winston");
const logger = new winston.Logger();
...
if( process.env.ELASTIC_SEARCH_LOGGING_URL ){

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: process.env.ELASTIC_SEARCH_LOGGING_URL,
log: 'info'
});

logger.add(
require('winston-elasticsearch'),
{
client
}
);
}
//this causes the error
logger.info("hi")

我看到这个:

clock_1 | TypeError: callback is not a function
clock_1 | at Elasticsearch.log (/usr/app/node_modules/winston-elasticsearch/index.js:105:5)
clock_1 | at transportLog (/usr/app/node_modules/winston/lib/winston/logger.js:234:15)
clock_1 | at /usr/app/node_modules/winston/node_modules/async/lib/async.js:157:13

我使用node@8.9、winston@2.4.1和winston-elasticsearch@0.7.0。 ELASTIC_SEARCH_LOGGING_URL 环境变量是准确的。

库中发生错误:

  log(info, callback) {
const level = info[LEVEL];
const { message } = info;
let meta = info[SPLAT];
if (meta !== undefined) {
// eslint-disable-next-line prefer-destructuring
meta = meta[0];
}

setImmediate(() => {
this.emit('logged', level);
});

const logData = {
message,
level,
meta,
// timestamp: this.opts.timestamp()
};
const entry = this.opts.transformer(logData);
this.bulkWriter.append(
this.getIndexName(this.opts),
this.opts.messageType,
entry
);

callback();
}

它正在调用未定义的“callback()”。

我配置错误吗?有没有更好的方法通过Winston将应用程序日志发送到ES?

最佳答案

需要winston 3.0 或更高版本。

const winston = require("winston"); //"winston": "~3",
const logger = winston.createLogger();

if( process.env.ELASTIC_SEARCH_LOGGING_URL ){

var elasticsearch = require('elasticsearch');
var winston_elasticsearch = require('winston-elasticsearch');

var client = new elasticsearch.Client({
host: process.env.ELASTIC_SEARCH_LOGGING_URL,
log: 'info'

});

logger.add( new winston_elasticsearch({
client,
index:"logging"
}));
}

winston-elasticsearch 开发人员的解决方案: https://github.com/vanthome/winston-elasticsearch/issues/69#issuecomment-430124467

关于node.js - winston-elasticsearch 在记录时创建回调错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52823107/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com