首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复错误: ConfigurationError: winston的缺失节点选项?

如何修复错误: ConfigurationError: winston的缺失节点选项?
EN

Stack Overflow用户
提问于 2019-10-14 06:37:34
回答 2查看 7.5K关注 0票数 5

我想在Cucumber中使用ElectricSearch日志,我创建了一个类Logger

代码语言:javascript
复制
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

在“黄瓜的前状态”中,我创建了一个记录器

代码语言:javascript
复制
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)

EN

回答 2

Stack Overflow用户

发布于 2021-06-15 15:40:45

如前所述,这里

您缺少elasticsearch客户端配置。

代码语言:javascript
复制
var esTransportOpts = {
   level: 'info',
   clientOpts: { node: 'http://localhost:9200' }
}

这样你就可以告诉温斯顿把原木放哪儿了。

票数 3
EN

Stack Overflow用户

发布于 2022-09-07 17:52:53

当我从elasticsearch移动到@弹性/elasticsearch时,我也遇到了同样的问题。我将winston.transports.Logstash参数中的属性host更改为带有http://前缀的node

发自:

代码语言:javascript
复制
const client = new elasticsearch.Client({
         host: '${esHost}:${esPort}',
      })

至:

代码语言:javascript
复制
const client = new elasticsearch.Client({
        node: 'http://${esHost}:${esPort}'
      })
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58371284

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档