gpt4 book ai didi

elasticsearch - 如何修复错误 : ConfigurationError: Missing node(s) option for winston-elasticsearch?

转载 作者:行者123 更新时间:2023-12-04 11:36:40 27 4
gpt4 key购买 nike

I want to use log with ElectricSearch in Cucumber I create a class Logger


var winston = require('winston');
var Elasticsearch = require('winston-elasticsearch');
var instance
var logger
var esTransportOpts = {
level: 'info'
}

class Logger {

constructor() {
logger = winston.createLogger({
transports: [
new Elasticsearch(esTransportOpts)
]
})
}

static getLogger() {
if (!instance) {
instance = new Logger()
}
return logger
}


createLogger () {
let logger = winston.createLogger({
level: 'info',
format: winston.format.json(),
defaultMeta: { service: 'user-service' },
transports: [

new winston.transports.File({ filename: 'combined.log' })
]
});

//
// If we're not in production then log to the `console` with the format:
// `${info.level}: ${info.message} JSON.stringify({ ...rest }) `
//
if (process.env.NODE_ENV !== 'production') {
logger.add(new winston.transports.Console({
format: winston.format.simple()
}));
}

}


static addLogging () {
winston.add(winston.transports.Logstash, {
port: 28777,
node_name: 'my node name',
host: '127.0.0.1'
});

}
}
module.exports = Logger

in the Before statment of Cucumber I create a logger


const { Before, Given, When, Then } = require('cucumber')
const Logger = require('../../src/Logger')

let a,b, r , logger


Before(function() {
logger = Logger.getLogger()
})

Given('I have first variable {int}', function (int) {
logger.info("Multipler")
a = int

});



Given('I have second variable {int}', function (int) {
b = int

});

When('Multiplication a and b', function() {
r = a*b
})



Then('I display the Result {int}', function (int) {
int = r
logger.info(a, "multiplyes with", b, "is", r )
return int
});

When I exeute this the cucumber test I get the error message:

cucumber2@0.1.0 cucumber /Users/steinkorsveien/Development/Cucumber/cucumber2 cucumber-js "systemtest/Multiplier.feature" F----

Failures:

1) Scenario: multiplying a and b # systemtest/Multiplier.feature:24
✖ Before # systemtest/step-definition/multiplier.js:7 ConfigurationError: Missing node(s) option at new Client (/Users/steinkorsveien/Development/Cucumber/cucumber2/node_modules/@elastic>/elasticsearch/index.js:52:13) at new Elasticsearch (/Users/steinkorsveien/Development/Cucumber/cucumber2/node_modules/winston->elasticsearch/index.js:57:21) at new Logger >(/Users/steinkorsveien/Development/Cucumber/cucumber2/src/Logger.js:13:16) at Function.getLogger >(/Users/steinkorsveien/Development/Cucumber/cucumber2/src/Logger.js:20:20) at World. >(/Users/steinkorsveien/Development/Cucumber/cucumber2/systemtest/step->definition/multiplier.js:8:30)

最佳答案

如前所述 here
您缺少 elasticsearch 客户端配置。

var esTransportOpts = {
level: 'info',
clientOpts: { node: 'http://localhost:9200' }
}
这样你就告诉 winston 在哪里转储日志。

关于elasticsearch - 如何修复错误 : ConfigurationError: Missing node(s) option for winston-elasticsearch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58371284/

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