我想在Cucumber中使用ElectricSearch日志,我创建了一个类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在“黄瓜的前状态”中,我创建了一个记录器
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
});当我退出这个黄瓜测试时,我得到了错误消息: 黄瓜2@0.1.0黄瓜/Users/steinkorsveien/Development/Cucumber/cucumber2黄瓜-js“系统测试/多重特性”F 失败: 1)场景:乘a和b#系统测试/乘法器。特性:24 前面的✖#systemtest/step-definition/Multiier.js:7 ConfigurationError:新客户端的缺失节点(S)选项,新的Elasticsearch (/Users/steinkorsveien/Development/Cucumber/cucumber2/node_modules/winston->elasticsearch/index.js:57:21) at new Logger >(/Users/steinkorsveien/ConfigurationError/Development)/Cucumber/cucumber2/src/Logger.js:13:16) >(/Users/steinkorsveien/Development/Cucumber/cucumber2/src/Logger.js:20:20) at Function.getLogger at World。>(/Users/steinkorsveien/Development/Cucumber/cucumber2/systemtest/step->definition/multiplier.js:8:30)
发布于 2021-06-15 15:40:45
如前所述,这里
您缺少elasticsearch客户端配置。
var esTransportOpts = {
level: 'info',
clientOpts: { node: 'http://localhost:9200' }
}这样你就可以告诉温斯顿把原木放哪儿了。
发布于 2022-09-07 17:52:53
当我从elasticsearch移动到@弹性/elasticsearch时,我也遇到了同样的问题。我将winston.transports.Logstash参数中的属性host更改为带有http://前缀的node。
发自:
const client = new elasticsearch.Client({
host: '${esHost}:${esPort}',
})至:
const client = new elasticsearch.Client({
node: 'http://${esHost}:${esPort}'
})https://stackoverflow.com/questions/58371284
复制相似问题